Java Regex Cheat Sheet



Regular Expressions Cheat Sheet by DaveChild - Cheatography.com Created Date: 4237Z. Regular Expressions Cheat Sheet for Python, PHP, Perl, JavaScript and Ruby developers. The list of the most important metacharacters you'll ever need.

Need a little extra help with those Regular Expression(regex) functions? Then look no further! Here, I have put together the best top 10 regex cheat sheets for you to download, print and pin to the bathroom wall!!

This cheat sheets will be a great reference when you need to put them in your scripts when you are web scraping and trying to find information or when you need help to authenticate users and passwords!

All the regex cheat sheets in this article are 100% free. All links open a new tab (feel free to open all the links without losing this page!)

Cheat Sheet 1: Rexegg.com

This first sheet is from Rexegg.com. The entire list is one that is commonly used Regex expressions in Python and other languages. This list includes Characters, Quantifiers and more. It will even tell you what language this expression can be used in! This makes it a lot easier when you go to write a regex in your language preference. This website really does emphasize looking at the tables for the expressions by keeping the tables bright on a black background. Making it easy to read the table but very difficult to read the information on regex itself.

Pros: Tables are bright and easy to read. Contains a lot of information shorthand to write regex

Cons: Information on the page is very dark and difficult to read.

Cheat Sheet 2: Regular Expressions cheat sheet – MIT

This second sheet was written by MIT. It is very spartan with no color and straight to the point on what the expressions are and what they do. This is the perfect cheat sheet if you do not want to be distracted by color or graphics. However, since it is very dry in the manner of text, I would not suggest this particular cheat sheet to someone who is just learning regular expressions since the explanations and examples are minimal.

Pros: Clean text, no colors for distraction, contains a lot of information shorthand to write regex

Cons: Too spartan for a total beginner in Regex

Cheat Sheet 3: Cheatography.com

I really love this website! This sheet was put together by Dave Child for regular expressions. It’s a nice quick reference guide pdf you can print in bright pink. It is easy to read and rated ‘E’ for everyone! It includes symbols, ranges, grouping, assertions and more with sample patterns to help get you on your way! Cheatography is one of my favorite websites for cheat sheet because they have so many on so many different topics and in many styles. It’s nice to find a one stop shop for cheat sheets.

Pros: Explains regex easily, uses soft colors, contains a lot of information.

Cons: Color may be distracting to some.

Cheat Sheet 4: Dev.to

Dev.to is a great place for new and experienced developers! This regex list was written by Catherine on her dev.to profile where she explains regex expressions in Java-script she has compiled with her resources at the bottom of here article.

Pros: Great spot to read someone else’s experience in regex and to gather new resources

Cons: More of an article than an actual pdf to print.

Cheat Sheet 5: Last Call – The Rapid API Blog

This is another great website for developers! This cheat sheet is also very easy to read and understand. It has additional resources beneath the code written. There are no examples in the post but there is shorthand explanations for each expression, characters and quantifiers. I would not suggest this particular cheat sheet for a beginner.

Pros: Great for those who understand regex and don’t have a need for examples

Cons: Not for Beginners since it has minimal explanation

Cheat Sheet 6: GREP

Here is another one! This one is minimal in color to keep distractions down. Key words are in red and examples are done in yellow. There are minimal explanations in the color keys. This sheet is for the advanced regex user who only needs a quick reference. It is clean and easy to read. It covers all of the information needed to write your own regex!

Pros: Written cleanly, additional resources at the bottom, to the point.

Java regex cheat sheet example

Cons: Not for the regex beginner.

Regular Expressions Cheat Sheet Pdf

Cheat Sheet 7: Regex chart

This Regex sheet is a very quick one with only the characters, the meaning and an example. This one is also for the advanced regex user. There is only the bare minimum here and this particular sheet does not contain quantifiers or expressions. There is a link however to a regex character classes cheat sheet.

Pros: Very quick reference of only character in regex

Sheet

Cons: Not for a beginner regex user.

Java regex cheat sheet excel

Cheat Sheet 8: Keycdn

Here is another awesome website to learn Regular expressions from! It goes over what regex is, gives you the list of expressions and gives you 2 separate examples on how regex is used in find numbers and emails. Near the bottom it even give you 3 tools to help you learn how to build a proper regex formula! These test sites will help you not only to build regex but compile it and make sure it running correctly before implementing it into your code.

Pros: Not only information but tools as well!

Cons: none as far I can see.

Cheat Sheet 9: MDN Web Docs

This regex syntax cheat sheet is on one of my absolute favorite places to learn about web development!! Named Moz:a (pronounced Mozilla) this particular guide will walk through not only the syntax but take you to the complete guide on regex! This cheat sheet is rated ‘E’ for everyone! It has clear examples and explanations on beginner and advanced regex characters and expressions.

Pros: Great for Everyone!!

Cons: N/A

Cheat Sheet 10: Dataquest

The final cheat sheet!! This final cheat sheet is from Dataquest. This particular cheat sheet was written specifically for Python!! This pdf is downloadable for free and explains each character and expression in detail. There is a lot of information packed in this pdf each under the proper heading and minimal color for the least number of distractions.

Pros: A lot of information pack in with minimal color.

Cons: Can appear to be overwhelming at first glance to a beginner.

Regular expression cheat sheet

I would like to thank you for taking the time to read this article. I hope that you are able to use at least one of these cheat sheets the next time you need to put a regular expression in your coding! The best way to learn though is to practice!! Good luck with writing your regex!!

Related Articles:

Related Posts

A regular expression, or just regex, is used to match patterns within the given string. Bellow is the cheat sheet of string matching I find useful. Enjoy!

Testing Methods

Java Regex Cheat Sheet Examples

  • Method test
  • Executes a search for a match within a given string. Returns true or false
  • Method match
  • Searches a given string for a match, and returns the matches in form of an array

Globals

Ignoring Case

  • The i flag
  • Ignores case within the string, makes the regex case insensitive

Global Lookup

  • The g flag
  • Searches for a pattern throughout the string and returns an array of found items

Pattern Matching

  • Starts with operator ^
  • Matches the characters at the beginning of a string
  • Ends with operator $
  • Matches the characters at the end of a string
  • The dot (wildcard) operator .
  • Matches any character, except newline
  • The or operator |
  • Matches multiple patterns within a given string
  • The word operator w
  • Matches all letters
  • The not word operator W
  • Matches all non-letter characters including whitespace
  • The digit operator d
  • Matches all digits
  • The not digit operator D
  • Matches all non-digit characters including whitespace
  • The whitespace operator s
  • Matches all whitespaces
  • The not whitespace operator S
  • Matches all except whitespaces

The list operator []

The output depends on what you put in between the brackets.

Java Regex Cheat Sheet For Beginners

  • Match any of
  • Match between characters

Java Regex Cheat Sheet Excel

  • Match numbers and letters

Quantifiers

Quantifiers can be greedy or lazy, depending on the regex definition. A greedy quantifier causes the regex engine to match as many occurrences of the given patterns as possible and vice versa, a lazy quantifier causes the engine to match as few occurrences as possible. Some of the greedy quantifiers are ?, ?, *, + and some of the lazy ones are ??, *?, +?.

Java Regex Cheat Sheet

  • Match zero or more *
Example
  • Match one or more +
  • Match zero or one ?
  • Match n times {n}

Java Regex Cheat Sheet

  • Match atleast n times {n,}

Regular Expression Cheat Sheet

  • Match between n and m times {n,m}