Finding words or String with same beginning and end using regular expressions with .net
In this regular expression we are going to find words or String with same beginning and end. Means we are going to search words like xerox with same beginning and end "x".
Regular Expression Pattern
\b(?<First>\w{1,})(?<Second>\w+)(?(Second)\k<First>)\b
A description of the regular expression:
First or last character in a word
[First]: A named capture group. [\w{1,}]
Alphanumeric, at least 1 repetitions
[Second]: A named capture group. [\w+]
Alphanumeric, one or more repetitions
Conditional Expression with "Yes" clause only
Did the capture named [Second] match?
If yes, search for [\k<First>]
Backreference to capture named: First
First or last character in a word
Sucessful Matches
xerox
404
rotor
rotor
ISAPI




