A Tiny Tutorial For Regular Expressions

Regular expressions, also known as regex, are a useful way to generalize text for text scraping for example. We can define tokens that generalize specific text snippets with regex (which is supported by many languages in addition to Java).

Regular Expression Example

How do I use regex?

We can import both java.util.regex.Matcher and java.util.regex.Pattern. Then, by initializing a Pattern object containing our regular expression, we can use a newly created Matcher object off of the pattern, with new text to parse through. Using the stringBuilder or find methods, we can determine if a match is found in our text!

Here's a list of regex expressions:

There are more regex tidbits to know, but for the sake of brevity, I'll stop here. In the meantime, here's a link for more information, and tools to play around and test different regex expressions!

Click here to go to regex101.com to have some fun with regexes