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

Java 9 Regular Expressions: A hands-on guide to implement zero-length assertions, back-references, quantifiers, and many more

Arrow left icon
Profile Icon Anubhava Srivastava
Arrow right icon
₱1113.99 ₱1591.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (2 Ratings)
eBook Jul 2017 158 pages 1st Edition
eBook
₱1113.99 ₱1591.99
Paperback
₱1989.99
Subscription
Free Trial
Arrow left icon
Profile Icon Anubhava Srivastava
Arrow right icon
₱1113.99 ₱1591.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (2 Ratings)
eBook Jul 2017 158 pages 1st Edition
eBook
₱1113.99 ₱1591.99
Paperback
₱1989.99
Subscription
Free Trial
eBook
₱1113.99 ₱1591.99
Paperback
₱1989.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Java 9 Regular Expressions

Understanding the Core Constructs of Java Regular Expressions

Using Java as a regular expression flavor, in this chapter, we will go a bit deeper and learn in detail about anchors, quantifiers, boundary matchers, all the available character classes, negated character classes, predefined character classes, and character classes escaping rules, using Java as a reference point. You will also learn Unicode text matching, using regular expressions in Java. We will also cover greedy versus non-greedy (lazy matching) and the change of regular expression behavior with lazy matching.

We will cover the following topics in this chapter:

  • Anchors and quantifiers
  • Boundary matchers
  • Character classes
  • Regex escaping rules
  • Escaping inside character classes
  • Negated character classes
  • Predefined character classes
  • Unicode characters matching
  • Greedy quantifiers
  • Lazy quantifiers
  • Possessive quantifiers...

Understanding the core constructs of regular expressions

Certain special character constructs are allowed literally in Java regular expressions. Here they are:

Special Character Meaning
\0c A character with the octal value c
\0cc A character with the octal value cc
\0ncc A character with the octal value ncc, where n cannot be more than 3
\xhh A character with the hexadecimal value 0xhh
\uhhhh A character with the hexadecimal value 0xhhhh
\x{h...h} A character with the hexadecimal value 0xh...h, where h must be a valid CODE_POINT
\n Newline character or u000A
\t Tab character or u0009
\r Carriage return character or u000D
\f Form feed character or u000C
\e Escape character or u\u001B
\a Bell character or \u0007
\cn A control character represented by n

Quantifiers

We briefly looked at quantifiers in the first chapter. Quantifiers allow us to quantify the occurrences of our matches. We can match the input in various ways, such as an optional match, an open-ended range, a closed range, and by using a fixed number. Let's take a closer look at them, as quantifiers are integral to most of the regular expressions.

Basic quantifiers

The following table lists all the quantifiers available in Java regular expressions:

...
Quantifier Meaning
m* Match m zero or more times
m+ Match m one or more times
m? Match m one or zero times (also called an optional match)
m{X} Match m exactly X times
m{X,} Match m X or more times
m{X,Y} Match m at least X and at most Y times

Summary

In this chapter, we covered the core constructs of regular expressions in depth. You learned anchors, quantifiers, boundary matchers, various character classes, negated character classes, and predefined character classes. We found out that escaped characters need to be escaped twice in the Java language. You also learned Unicode text matching using regular expressions in Java. We covered greedy, non-greedy, and possessive quantifiers. You learned embedded mode modifiers in Java regular expressions and how they can change the interpretation of a regular expression.

In the next chapter, we will cover another very important feature of regular expressions, called grouping. You will learn the various types of grouping available in Java regular expressions and how to use them.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Discover regular expressions and how they work
  • Implement regular expressions with Java to your code base
  • Learn to use regular expressions in emails, URLs, paths, and IP addresses

Description

Regular expressions are a powerful tool in the programmer's toolbox and allow pattern matching. They are also used for manipulating text and data. This book will provide you with the know-how (and practical examples) to solve real-world problems using regex in Java. You will begin by discovering what regular expressions are and how they work with Java. This easy-to-follow guide is a great place from which to familiarize yourself with the core concepts of regular expressions and to master its implementation with the features of Java 9. You will learn how to match, extract, and transform text by matching specific words, characters, and patterns. You will learn when and where to apply the methods for finding patterns in digits, letters, Unicode characters, and string literals. Going forward, you will learn to use zero-length assertions and lookarounds, parsing the source code, and processing the log files. Finally, you will master tips, tricks, and best practices in regex with Java.

Who is this book for?

This book is for Java developers who would like to understand and use regular expressions. A basic knowledge of Java is assumed.

What you will learn

  • Understand the semantics, rules, and core concepts of writing Java code involving regular expressions
  • Learn about the java.util.Regex package using the Pattern class, Matcher class, code snippets, and more
  • Match and capture text in regex and use back-references to the captured groups
  • Explore Regex using Java String methods and regex capabilities in the Java Scanner API
  • Use zero-width assertions and lookarounds in regex
  • Test and optimize a poorly performing regex and various other performance tips

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 25, 2017
Length: 158 pages
Edition : 1st
Language : English
ISBN-13 : 9781787288034
Vendor :
Oracle
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jul 25, 2017
Length: 158 pages
Edition : 1st
Language : English
ISBN-13 : 9781787288034
Vendor :
Oracle
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 7,297.97
Distributed Computing in Java 9
₱2500.99
Java 9 Regular Expressions
₱1989.99
Java 9 Programming Blueprints
₱2806.99
Total 7,297.97 Stars icon

Table of Contents

8 Chapters
Getting Started with Regular Expressions Chevron down icon Chevron up icon
Understanding the Core Constructs of Java Regular Expressions Chevron down icon Chevron up icon
Working with Groups, Capturing, and References Chevron down icon Chevron up icon
Regular Expression Programming Using Java String and Scanner APIs Chevron down icon Chevron up icon
Introduction to Java Regular Expression APIs - Pattern and Matcher Classes Chevron down icon Chevron up icon
Exploring Zero-Width Assertions, Lookarounds, and Atomic Groups Chevron down icon Chevron up icon
Understanding the Union, Intersection, and Subtraction of Character Classes Chevron down icon Chevron up icon
Regular Expression Pitfalls, Optimization, and Performance Improvements Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(2 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Amazon Customer Jun 08, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is enough to have an in depth knowledge in Regular expressions.
Amazon Verified review Amazon
Justin Apr 19, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Amazingly insightful, here is a man that really knows his stuff and will help you figure out the most in depth problems. I would recommend this to anyone who actually wants to know how to solve problems with regex.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.