i trying determine if string contains @ least 1 xml tag using string.match() function. due way project set up, prefer if didn't have use pattern.
currently use regex:
<[a-za-z0-9]+> which checks if string has right , left arrow brackets contains text. need way check if string has single xml tag regex, eg input like:
blah <abc foo="bar">blah</abc> blah blah <abc foo="bar"/> but not input like:
blah <abc> blah blah <abc </abc> blah is possible?
this:
if (input.matches("(?s).*(<(\\w+)[^>]*>.*</\\2>|<(\\w+)[^>]*/>).*")) matches both types of tag (standard , self-closing):
<abc foo="bar">blah</abc> <abc foo="bar"/> without matching incomplete tags like:
<abc> see regex live demo.
Comments
Post a Comment