このチュートリアルから、「正規表現 - 量指定子」について学び、このチュートリアルで使用されるこのテスト コードに基づいています。
これらのテストについて質問があります。
Enter your regex: ab*foo
Enter input string to search: xabfooxxxabbbfoox
I found the text "abfoo" starting at index 1 and ending at index 6.
I found the text "abbbfoo" starting at index 9 and ending at index 16.
しかし
Enter your regex: a.*foo
Enter input string to search: xabfooxxxabbbfoox
I found the text "abfooxxxabbbfoo" starting at index 1 and ending at index 16.
これらではない理由:
I found the text "abfoo" starting at index 1 and ending at index 6.
I found the text "abbbfoo" starting at index 9 and ending at index 16.
一般的に、私はいつも.*
または.+
使用されていることに気付きました:
一致する場合は 1 つだけです。
文字列の一致するセクションは常に最長のものです。
では、それぞれのマッチングはどのように機能するのでしょうか?