Regular Expressions: An Introduction
Published: January 12, 2004
User Rating: 8.9 (282 votes)
Positional Matching
Positional matching allows you to match the pattern with the start and end of the subject.
- ^: Match Start of the subject (or start of the line, in multi-line mode)
- $: Match End of the subject (or end of the line, in multi-line mode)
- \A: Match Start of the subject (independent of multi-line mode)
- \z: Match End of the subject (independent of multi-line mode)
Taking a few examples
Regex /.*abcd.*/
Equivalent to /abcd/
Explaintaion Match anything, followed by "abcd", followed by anything
Regex /^abcd.*/
Explaintaion Match starting "abcd", followed by anything
Example abcd True
abcde True
abcdef True
xyzabcd False
xyzabcdef False
Regex /abcd$/
Explaintaion Match ending "abcd"
Example abcd True
abcde False
abcdef False
xyzabcd True
xyzabcdef False
Regex /^abcd$/
Explaintaion Match starting and ending "abcd"
Example abcd True
abcde False
abcdef False
xyzabcd False
xyzabcdef False
About
Amit Arora is web developer with expertise in developing eCommerce enabled websites for the businesses.

Monitored by Site24x7
Uptime