Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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 (15) Chapters Close

Title page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Getting Started with Regular Expressions FREE CHAPTER 2. Understanding the Core Constructs of Java Regular Expressions 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 Matcher class


An instance of the Matcher class performs various match operations on a character sequence by interpreting a compiled regular expression represented by an instance of Pattern. This is how we use this class to match a regex:

  • We create a matcher instance from a pattern by invoking the pattern's matcher method that requires the input sequence as argument
  • The instance of matcher is used to perform three types of match operations using these three methods, each returning a Boolean value (true indicates success):
    • matches
    • find
    • lookingAt

These methods perform the matching in the following manner:

  • The matches method attempts to match the complete input sequence using the matcher's pattern
  • The find method searches the input sequence for the next substring that matches the pattern
  • The lookingAt method attempts to match the input sequence using the matcher's pattern at the start position.

Let's list down all the important methods from the Matcher class here:

Method Signature

Description

boolean...

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 £13.99/month. Cancel anytime
Visually different images