Some of them are listed below :
Using ^ and $ Symbols
Lets us take a look at the 2 special symbols ^ and $ . These symbols indicates the starting and ending of the string .
As for Example :
“^Interview” : Matches any string starting with the Interview.
“Questions$” : Matches any string ending with Questions .
“^Interview$” : Matches the that starts and end with Interview.
“Questions” : Matches the string that has text Questions in it
The last example indicate that the pattern can match or occur anywhere in the string. the search pattern are not bounded with any edge i.e either starting or ending .
Using *,+ and ? Symbols
The Symbols “*” , “+” , “?” denotes the number of times the pattern/characters appears in the string .
- “*” means zero or more
- “+” means one or more
- “?” means zero or one
“pi*” : Matches the string that has character(s) followed by zero or more i , i.e the possibilities are “p” , “pi” , “pii” and so one…
“p?i+$*” : Matches the string that may have character(s) but compulsorily ends with at least one or more i i.e the possibilities are “i” , “pi” , “pii” , “piq” and so one…
Using Bounds {}
Bounds can also be used , which comes inside the braces and indicates the ranges in the terms of occurrences .
They are used as :
To quantify a sequence of characters , put them inside the round bracket .
They are used as :
- “p(iq)*” : Matches the string that has characters followed by zero or more copies of the sequence “iq” .
- “p(iq){1,5}” : Matches the string that has characters followed at least one but not more than fove copies of the sequence “iq”.
- “Shah|Mr.Shah” : Matches the string that holds either Shah or Mr.Shah.
- “(Shah | Shaha) Professor ” : Matches the string that holds either ShahProfessor ornShahaProfessor .
- “(p|i)*q” : Matches the string that has sequences of characters i.e “pq” ,”ppq” , “pppq” and so on , “iq”,”iiq” ,”iiiq” and so on .
- “s.[0-9]” : Match the string that has a characters followed by any one character further followed by the digit. The Possibilities are “s1” , “s2” and and so on …
- “^.{5}$” : Matches the string exactly with the eight characters , The possibilities are “mango” , “apple” and so on .
- “[pq]” : Match the string that has either character p or q . It is similar to p|q.
- “[a-d]” : Match the string that holds the characters through a to d . This is equal to “a|b|c|d” or “[abcd]” .
- “^[a-zA-Z]” : Matches the string that begins with the letter .
- “[0-9]%” : Matches the string that has single digit before the percent sign .
- “,[a-zA-z0-9]$” : Matches the string that ends with comma followed by digits .
- “%[^a-zA-Z]% : Matches the string with a character that is not an alphabet between the two percent signs .