Smartly Subbing: Finding Substring Patterns Within a String

The section "Staying Regular: Using Regular Expressions to Search Text" at the beginning of this chapter describes how to use a regex pattern to compare whether a String matches (or partially matches) a given pattern, starting from the beginning of the input String. In this section, we'll be using regex patterns to find multiple matching values within a String. As an example, we'll search within a document to find any URLs embedded in the text. First, we'll need a pattern String that matches URLs. Here is one pattern that will match most URLs in common usage:

 String urlString = ...

Get Wicked Cool Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.