An Introduction to Regular Expressions The Basics 21 of 50 : [PREV] [NEXT]

Standard Meta Characters

Backreferences (continued)

Within the same regular expression, use a backslash followed by an integer as a backreference. The integer corresponding to a given pair of parentheses is determined by counting left parentheses from the beginning of the pattern. The following regular expression matches something similar to an HTML tag (like text here):

/<(.*)>.*<\/\1>/

The following regular expression matches a string (at least four-characters long) whose first two characters are also its last two characters, but in reverse order (such as "abcdefba"):

/^(.)(.).*\2\1$/

© 2003 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/