Regex searching for number and letter combination optional brackets -
i need regex find match of single lower case a-z character followed 5 numbers either:
- at start of line
- at end of line
- surrounded () or []
- surrounded whitespace
so following results expected:
a12345 match
(a12345) match
[a12345] match
text a12345 match
aa12345 no match
at moment have (?<=[])]*)[a-z]{1}[0-9]{5}(?=[])]*)
not working scenarios, example sees aa12345 , a12345a being matches when don't want them to.
can help?
edit: apologies should have mentioned .net c#
first of should mention programming language.
following solution pcre.
regex: ((?<=[\[( ])|^)[a-z]\d{5}((?=[\]\) ])|$)
explanation:
((?<=[\[( ])|^)
checks preceding brackets, whitespaces or beginning.[a-z]\d{5}
checks alphabet followed 5 digits.((?=[\]\) ])|$)
checks succeeding brackets, whitespaces or end of line.
Comments
Post a Comment