I was amused but his advice made me to think otherwise and I have been since then trying to dig deep in to this issue.
I always have issues with JS regexes so I've thrown them out for the most part and just make a stinking AJAX request and send them to a much more robust PHP regex I use now, but this one works and I use it some times.
(This tutorial is not complete, see part 2 soon)
Regular Expression Definition:
In computing, regular expressions, also referred to as regex or regexp, provide a concise and flexible means for matching strings of text such as particular characters, words, or patterns of characters.
var rex = /pattern/modifiers
Here pattern specifies the pattern or type of the regular expression e-g the pattern of email id is [email protected] and not something that contains @ and . only.
Modifiers specify how we want out patters to be matched. e-g: putting i as a modifier means that we are interested in case insensitive match of our regular expression.
Pattern matching characters are numerous and hence are grouped in to various categories:
If you wish to match a certain character that happens to be at a specific position in a sequence. E-g a substring that may happen to be an initial character or say some five characters behind the start of sequence or say at the end of the sequence:
1: Caret(^): ^ matches only the beginning of the string. E-g:
a: /^singularity/ matches “singularity” in “singularity is yet to come ” and not “when is singularity gonna happen”
(The modifier i is used to signify a case insensitive match)
c: /^singularity/i matches “SinGUlaRiTy” or “sINgUlaRity” or “singularity” in “singularity is yet to come ” or “sIngUlariTy is yet to come ”and not “when is singularity gonna happen”
2: Dollar($): $ matches only the end of the string E-g:
a: /organ$/ matches “organ” in “microorgan” but not in “organismic”
3: Boundary Character(\b):\b matches any boundary character. i-e it should be either at the beginning or at the end of the string. E-g:
a: /ly\b/ matches “ly” in “This is really Cool.”
4: Non Boundary Character(\B): E-g:
a: /\Bor/ matches “or” in “normal” but not in “organisms”.