我正在elisp中進行一些解析,並且我有一個我已部分消耗的字符串(讓我們假設其值爲"foobar123"
)。假設我已經使用了"foobar"
(所以我知道我需要從char 6開始分析),並且期望消耗2
。匹配elisp正則表達式中的搜索開始位置
我試過以下,沒有一個做我想要的。
(string-match "2" "foobar123" 6) ; Matches the `2` at character 7.
(string-match "^2" "foobar23" 6) ; Not at the beginning of line.
(string-match "\\`2" "foobar23" 6) ; Not at the beginning of string.
我已經成功拉出一子,並針對匹配(即(string-match "^2" (substring "foobar23" 6))
),但這似乎浪費。這感覺就像我想要一個特殊字符,意思是「只在搜索開始時匹配」,但我找不到一個。有沒有更好的辦法?
沒有我知道的這樣的正則表達式語法。另一種解決方案可能是將字符串插入緩衝區,當您使用字符串時移動該點並使用'\ ='結構來匹配點。 – Lindydancer
把它作爲一個明確的答案,我會接受。 –