Regex to match tag contents while simultaneously omitting leading and trailing whitespace -
Regex to match tag contents while simultaneously omitting leading and trailing whitespace -
i trying write regex matches entire contents of tag, minus leading or trailing whitespace. here boiled-down illustration of input:
<tag> text </tag>
i want next matched (note how whitespace before , after match has been trimmed):
"text"
i trying utilize regex in .net (powershell):
(?<=<tag>(\s)*).*?(?=(\s)*</tag>) however, regex matches "text" plus leading whitespace within of tag, undesired. how can prepare regex work expected?
drop lookarounds; create job more complicated needs be. instead, utilize capturing grouping pick out part want:
<tag>\s*(.*?)\s*</tag> the part want available $matches[1].
regex whitespace lookbehind lookahead removing-whitespace
Comments
Post a Comment