David T.
David T.

Reputation: 23439

How to match exact sequence with Pattern compile

I'm trying to use Linkify but can't seem to get the Pattern.compile() part down.

Let's say i have a string like blah blah hi Hello world! can you match me?

i want to match and linkify ONLY Hello world! and nothing else. i was trying to play around with this regex: Pattern pattern = Pattern.compile("\\bHello world!\\b"); but it doesn't seem to be matching at the exclamation mark.

what's the best way to match for an EXACT sequence of characters?

Upvotes: 0

Views: 494

Answers (1)

Loading BG
Loading BG

Reputation: 131

Using regexs, you can use ^ at the beginning and $ at the end:

Pattern pattern = Pattern.compile("^Hello world!$");

Also this question is a repeat of this.

Upvotes: 0

Related Questions