Other Resources:
Backreferences \g1, \g2, ...
What is a backreference? How to use a backreference?
How to write a regular expression using a backreferences to capture 5-letter reversible words in a text string like this: civic, level, radar, rotor or stats?
✍: FYIcenter.com
![]()
Backreferences are references representing catured sub strings already matched in earlier groups. Backreferences are expressed as \g1, \g2, ... with \g1 referring the sub string resulted from the first group. For example:
(\w+)\s+\g1 # match the same word repeated
The regular expression to match 5-letter reversible words is:
(\w)(\w)\w\g2\g1
(\w) - matches the first letter and capture it as the first group
(\w) - matches the second letter and capture it as the second group
\w - matches the third letter
\g2 - the fourth letter must match the second group result
\g1 - the fifth letter must match the first group result
2013-01-23, 0👍, 0💬
Popular Posts:
All credit card numbers issued by American Express must start with 34 or 37 and have 15 digits. For ...
How to capture the Baidu spider entries from Web log file? Here are some Web log file entries: 127.0...
All credit card numbers issued by Diners Club must start with 300 through 305, 36 or 38 and have 14 ...
How to capture the MSN (Microsoft Network) bot entries from Web log file? Here are some Web log file...
All credit card numbers issued by American Express must start with 34 or 37 and have 15 digits. For ...