從此tutorial我瞭解了「正則表達式 - 量詞」,並基於此教程中使用的test code。正則表達式:爲什麼?模式匹配任何字符串中的空字符串「」,包括「a」本身?
Enter your regex: a??
Enter input string to search: a
I found the text "" starting at index 0 and ending at index 0.
I found the text "" starting at index 1 and ending at index 1.
而且
Enter your regex: a??
Enter input string to search: aaa
I found the text "" starting at index 0 and ending at index 0.
I found the text "" starting at index 1 and ending at index 1.
I found the text "" starting at index 2 and ending at index 2.
I found the text "" starting at index 3 and ending at index 3.
而且
Enter your regex: a??
Enter input string to search: cab
I found the text "" starting at index 0 and ending at index 0.
I found the text "" starting at index 1 and ending at index 1.
I found the text "" starting at index 2 and ending at index 2.
I found the text "" starting at index 3 and ending at index 3.
爲什麼?
+1 @Cerbrus:這也回答你的問題。 – tripleee