Symbols used in Regular Expressions in Php



(1)         Using ^ and $:

ð   The ^ symbol indicate the start of a string and $ symbol indicate the
end of a string.
ð   For example:
ð    ^Shah”: matches any string that starts with Shah.
ð   “Shah$”: Matches any string that ends with Shah.
ð   ^Shah$”: Matches any string that starts and ends with Shah.
ð   Analyst”: matches any string that has the text Analyst.

(2)       Using *, + and ?

ð   The symbols like *, “+ and ?, denote the number of times a character or a sequence of characters may occur. The “* means zero or more, + means one or more and ? means zero or one.
ð    For example:
1) “sh*”: Matches a string that has a character s followed by zero or more h. The possibilities are “s”, “sh”, shh” and so on.
2)  “sh+: Matches a string that has a character s followed by at least
one or more h. The possibilities are “sh, “shhand so on.
3) “sh?: Matches the string that may have a character s but may or may not be followed by a single character h. The possibilities are “s”,
“sh”.
4)  “s?h+$: Matches the string that may have a character s but compulsory ends with at least one or more h. The possibilities are h”, “sh”, “shh, “shah and so on.

(3)      Using Bounds { }

ð   Bounds can also be used which come inside braces and indicate ranges in the terms of occurrences.

ð   For example:


1)“sh{2}”: Matches a string that has character s followed by exactly two h. The possibility is “shh”.
2) “sh{2 ,}”: Matches a string that has a character s followed by at least two h. The possibilities are “shh”, “shhh” and so on.
3) “sh{3,5}”: Matches a string that has a character s followed by at least three but not more tha five h. The possibilities are “shhh”,
“shhhh”, “shhhhh”.


Symbols used in Regular Expressions in Php Symbols used in Regular Expressions in Php Reviewed by Unknown on 11:21:00 PM Rating: 5

No comments:

Powered by Blogger.