DEV Community

Jack Cole
Jack Cole

Posted on

Learning Regex in Javascript Part 2

In this post I'll be be wrapping up my first post on regex. In a similar fashion to my last post, I'll be sure to provide examples that show the inputs and outputs. Let's jump into it!

Some Shortcuts

There are a ton of characters you can use in your regex to create unique specifications in your queries. I'll list a bunch below.

  • . gets any character that's not a line break
  • \s gets a white space
  • \S gets a non-white space
  • \d gets a digit
  • \D gets a non-digit

Regex

Only the Start or End

If you want to find a character at the beginning or end of your string, you can use ^ or $.

regex

The Caret (^)

^ also has a second use. When used inside of brackets, ^ indicates that you want anything except what's in the brackets.

Regex

Quantifiers

Quantifiers specify how many of the specified characters we want.

  • ? means zero or one
  • * means zero or more
  • + means one or more
  • {} specifies the exact quantity

Quantifiers

Special Characters

Finally, if you want to capture any special characters you need to precede them with a \.

Special Characters

Top comments (0)