java - Find multiple matches using Regex -
i trying find occurrences (there 0 or more) of anchor(<a>
) html tags specific attributes/text (to captured groups).
regex: <a\s+.*attr1="myattr".*attr2="(.+)".*attr3="(.+)".*>(.+)</a>
input string:
first <a attr1="myattr" attr2="value12" attr3="value13">text1</a> second <a attr1="myattr" attr2="value12" attr3="value13">text1</ a> third <a attr1="myattr" attr2="value12" attr3="value13">text1</a>
outcome: says 1 occurrence found. returning first occurrence of "<a
" starting index (of match) correct, says last occurrence of "</a>
" end index. expected outcome: 3 matches , in each match 3 groups (specified parentheses in regex).
regex default greedy, .*
match many characters possible. should instead use .*?
non-greedy mode.
Comments
Post a Comment