Find the right side (value) of expression in Java.

A simple example using RegEx:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
Pattern pattern = Pattern.compile("[\\d\\w\\s'\"]+\\z");
Matcher matcher = pattern.matcher("value=\"hello my name is bob\"");
while (matcher.find()) {
  System.out.print("found:'"+matcher.group()+"'");
}

prints…

found:'”hello my name is bob”‘

This will work for strings containing apostrophes and quotes too. Any quotes (“) must first be escaped with a \ in the search string.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s