我从这个链接中看到这两个边界匹配非常相似:
\G
和^
.
我还看到了他们在同一链接\G
末尾显示的示例。
Enter your regex: dog
Enter input string to search: dog dog
I found the text "dog" starting at index 0 and ending at index 3.
I found the text "dog" starting at index 4 and ending at index 7.
Enter your regex: \Gdog
Enter input string to search: dog dog
I found the text "dog" starting at index 0 and ending at index 3.
与没有边界匹配器相比,这非常清楚,但是:
Enter your regex: \Gdog
Enter input string to search: dog dog
I found the text "dog" starting at index 0 and ending at index 3.
对比
Enter your regex: ^dog
Enter input string to search: dog dog
I found the text "dog" starting at index 0 and ending at index 3.
2之间有什么细微的区别?