Different Expressions

PatternDescription
[a-z]Match a single character from a to z
[0-9]Match a single digit from 0 to 9
[<any-char-or-string>]Match a single character present in the set
[^<any-char-or-string>]Match a single character not present in the set
\dRepresent any digit
\DRepresent anything but not a digit
\sRepresent any space
\SAnything but not a space
\wAny character with (digits and alphabets)
\WAnything but not character(digits and alphabets)
\bFind a match at the beginning or end of a word. (word - boundry)
\BFind a match if there is another char at the beginning or end of a word. (Non-word boundry)
\0Find a NUL character
\nFind a new line character
\fFind a form feed character
\rFind a carriage return character
\tFind a tab character
\vFind a vertical tab character
\xxxFind the character specified by an octal number xxx
\xddFind the character specified by a hexadecimal number dd
\uxxxxFind the Unicode character specified by a hexadecimal number xxxx
.Represent any character except a line break
?0 or 1 repetitions
*0 or more repetitions
+1 or more repetitions
/**/igm

 i -  Perform case-insensitive matching

 g - Perform a global match (find all matches rather than stopping after the first match)

 m - Perform multiline matching

/$**/here $ means pattern match from the starting.
/**^/here ^ means pattern match from the end.

 

Quantifiers

QuantifierDescription
n+Matches any string that contains at least one n
n*Matches any string that contains zero or more occurrences of n
n?Matches any string that contains zero or one occurrences of n
n{X}Matches any string that contains a sequence of X n's
n{X,Y}Matches any string that contains a sequence of X to Y n's
n{X,}Matches any string that contains a sequence of at least X n's
n$Matches any string with n at the end of it
^nMatches any string with n at the beginning of it
?=nMatches any string that is followed by a specific string n
?!nMatches any string that is not followed by a specific string n

 

Different Examples :-

\b and \B

Dummy string to test :- "This is for any character (number + alphabet) and + disd for 1 or more characters $100"

search : is

1. Regex for \b : /\bis\b/
2. Regex for \B : /\Bis\B/

 

  • regex
  • regular-expression