Skip to content

Instantly share code, notes, and snippets.

@Sayan-Roy-729
Last active May 16, 2021 16:34
Show Gist options
  • Save Sayan-Roy-729/4cad3b4401965fac4dfcb5730f85dcb4 to your computer and use it in GitHub Desktop.
Save Sayan-Roy-729/4cad3b4401965fac4dfcb5730f85dcb4 to your computer and use it in GitHub Desktop.

Javascript

For tutorial video click here

Character Sets:

  • The below regular expression code will match with all those words which first letter should be a or b or c or 1 or 2 or 3 and next 3 characters should be 000. Besides this, no word will be match. E.g. a000 b000 2000 should match but e000 will not match.
/[abc123]000/
  • The below regular expression will match all the words those has last 3 characters 000 and the first character will be everything except p & e. e.g. a000 b000 2000 e000 will be match but p000 will not match
/[^pe]000/

Range:

  • Match all the words that have 000 as last 3 characters and first letter should be anything. Thaen range regular expression should be used. Regular expression is case sensitive, so add all small characters and capital characters. e.g. A000 a000 d000 x000 should be match but 2000 should not match.
[a-zA-Z]000
  • First letter should be any character a - z including lower case and capital case and also any number. Then next 3 characters should be 000.
[a-zA-Z0-9]000

Repeating Characters:

  • Match the numbers and the length is not specified. So any length of number word should be match.
/[0-9]+/
  • Match only 11 length numbers like phone numbers.
/[0-9]{11}/
  • Match all the characters but the lenght should be between 5 & 8. e.g. helloworld will match upto r, then rest charactes should not match. But first 8 characters will match.
/[a-z]{5,8}/
  • Match atleast 5 character long number. More than 5 characters number also should be match.
/[0-9]{5,}/

Metacharacters:

  • \d match any digit character (same as [0-9]). d matches the literal character, 'd' but \d matches any digit character.
  • \w match any word character (a-z, A-Z, 0-9 and _'s)
  • \s match a whitespace character (spaces, tabs etc)
  • \t match a tab character only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment