: uses a greedy quantifier to match a in abaa one or more times. The following output results:Regex = a+
Text = abaa
Found a
starting at index 0 and ending at index 1Found aa
starting at index 2 and ending at index 4The output reveals two matches. Unlike
a? and a*, a+ does not match the absence of a. Thus, no zero-length matches result. Like a*, a+ matches all consecutive as. - java RegexDemo a{2} aababbaaaab
:uses a greedy quantifier to match everyaasequence inaababbaaaab. The following output results:
Regex = a{2}Text = aababbaaaab
Found aa
starting at index 0 and ending at index 2Found aa
starting at index 6 and ending at index 8Found aa
starting at index 8 and ending at index 10- java RegexDemo a{2,} aababbaaaab
:uses a greedy quantifier to match two or more consecutiveas inaababbaaaab. The following output results:
Regex = a{2,}Text = aababbaaaab
Found aa
starting at index 0 and ending at index 2Found aaaa
starting at index 6 and ending at index 10- java RegexDemo a{1,3} aababbaaaab
:uses a greedy quantifier to match everya,aa, oraaainaababbaaaab. The following output results:
Regex = a{1,3}Text = aababbaaaab
Found aa
starting at index 0 and ending at index 2Found a
starting at index 3 and ending at index 4Found aaa
starting at index 6 and ending at index 9Found a
starting at index 9 and ending at index 10- java RegexDemo a+? abaa
:uses a reluctant quantifier to matchainabaaone or more times. The following output results:
Regex = a+?
Text = abaa
Found a
starting at index 0 and ending at index 1Found a
starting at index 2 and ending at index 3Found a
starting at index 3 and ending at index 4Unlike its greedy variant in the third example, the reluctant example produces three matches of a single
a because the reluctant quantifier tries to find the shortest match.
No comments:
Post a Comment