DEV Community

Jack Cole
Jack Cole

Posted on

4 1

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay