Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Java 9 Regular Expressions

You're reading from   Java 9 Regular Expressions A hands-on guide to implement zero-length assertions, back-references, quantifiers, and many more

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher Packt
ISBN-13 9781787288706
Length 158 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Anubhava Srivastava Anubhava Srivastava
Author Profile Icon Anubhava Srivastava
Anubhava Srivastava
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Getting Started with Regular Expressions 2. Understanding the Core Constructs of Java Regular Expressions FREE CHAPTER 3. Working with Groups, Capturing, and References 4. Regular Expression Programming Using Java String and Scanner APIs 5. Introduction to Java Regular Expression APIs - Pattern and Matcher Classes 6. Exploring Zero-Width Assertions, Lookarounds, and Atomic Groups 7. Understanding the Union, Intersection, and Subtraction of Character Classes 8. Regular Expression Pitfalls, Optimization, and Performance Improvements

The Pattern class


The Pattern class represents the compiled form of a string regular expression. So far, we have provided all the regular expressions as strings. Each String regular expression must be compiled into an instance of the Pattern class before the Java regex engine can execute it. An instance of the Pattern class is used to create a Matcher object to match input text against the regular expression.

Let's list down the important and useful methods from the Pattern class first:

Method Signature

Description

Static Pattern compile(String regex)

Compiles the given String regular expression into a Pattern instance.

Static Pattern compile(String regex, int flags)

Compiles the given String regular expression into a Pattern instance with the given flags. Flags can be one or more of DOTALL, MULTILINE, CASE_SENSITIVE, UNICODE_CHARACTER_CLASS and a few others. Check the Java Pattern API at http://download.java.net/java/jdk9/docs/api/java/util/regex/Pattern.html for all flags and their descriptions...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime