sample data
Reference # 12345678
Regex I have tried this regex:
(?<=Reference #)[ ]\d{8}\b
I am getting space inside the match, how to remove it from the match and put in the look behind instead.
>Solution :
In PCRE (the option you used at the regex testing online Web site), you can use
Reference\s+#\s+\K\d{8}\b
See the regex demo.
In .NET, you can use
(?<=Reference\s+#\s+)\d{8}\b
See this regex demo.
Details:
(?<=Reference\s+#\s+)– a positive lookbehind that matches a location that is immediately preceded withReference+ one or more whitespaces,#and then one or more whitespacesReference– a word\s+#\s+– a#char with one or more whitespaces both on the left and right\K– a match reset operator that discards the text matched so far from the overall match memory buffer\d{8}– eight digits\b– a word boundary (you might want to replace it with a right-hand digit boundary,(?!\d), if you plan to get a match if the eight digits are bordering on a letter or underscore).