.Net Regex match only if input ends or with Newline/Whitespace -
i have .net regex works expected (should match value after particular identifier key followed optional set of whitespace separated values within brackets, see http://regex101.com/r/yw4az3/113), matches bit loosely.
basically should match if match , optional () either followed input's end, 1 or more whitespaces or newline(s).
the regex used is:
^identifier ([a-za-z0-9-_]+)(?:\(([^)(]*)\))?
and sample(s) are:
identifier abc sdfadf << should match 'abc' identifier a_123bc(def) << should match 'a_123bc' , 'def' identifier abcdef~ << match should not match because 'abcdef' not followed either line end, whitespace(s) or newline(s)
does know how aforementioned example?
try utilize positive lookahead (for more details see illustration article). example, if add together (?=\s|$)
@ end of regex, match strings followed whitespace or end of string without matching whitespace:
^identifier ([a-za-z0-9-_]+)(?:\(([^)(]*)\))?(?=\s|$)
.net regex
No comments:
Post a Comment