Skip to content

Instantly share code, notes, and snippets.

@sagarnayak
Last active October 1, 2019 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagarnayak/826bcb7e50da375c7d18b33c6306c767 to your computer and use it in GitHub Desktop.
Save sagarnayak/826bcb7e50da375c7d18b33c6306c767 to your computer and use it in GitHub Desktop.
regular expression

Regular Expression

Used to match the string in a sequence of chars. Regular expression is case sensitive.

Searching for literal Chars

  • this is the simplest of all searches. to search ABC just do ABC.

Searching for reserved chars

  • there are some reserved keywords in Regular Expression which has special meaning. like . . so to search for a . we can not just write it like that. we need to escape it. like \. .
  • other special chars in regular expression are - .[{()^$|?*+

Using complex patterns

Pattern Description
. Any Character Except New Line
\d Digit (0-9)
\D Not a Digit (0-9)
\w Word Character (a-z, A-Z, 0-9, _)
\W Not a Word Character
\s Whitespace (space, tab, newline)
\S Not Whitespace (space, tab, newline)
\b Word Boundary
\B Not a Word Boundary
^ Beginning of a String
$ End of a String
[] Matches Characters in brackets
[^ ] Matches Characters NOT in brackets
| Either Or
( ) Group

Quantifiers:

Pattern Description
* 0 or More
+ 1 or More
? 0 or One
{3} Exact Number
{3,4} Range of Numbers (Minimum, Maximum)

Reference video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment