Skip to main content

[regex help]Find EXACT characters in a String.

1 reply [Last post]
Joined: 2009-05-20

Ok, i got this so far ...

<br />
import java.util.regex.Matcher;<br />
import java.util.regex.Pattern;</p>
<p>public class Testing2 {</p>
<p>    public static void main(String[] args) {<br />
        Pattern p = Pattern.compile("[wati]");<br />
        String text = "water";<br />
        Matcher m = p.matcher(text);<br />
        if (m.find()) {<br />
            System.out.print("Found !");<br />
        }<br />
    }<br />
}<br />

With that code i got a match, but i ONLY want to find a match if the String matches the EXACTS characters in the Pattern ...

in this case i got, 'w' 'a' 't' 'i', 'w' 'a' 't', are in water, but 'i' NOT, so i don't want to have a match !

i don't know how to acomplish this :(

hope you can help me, thanks in advance :D

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-11-01

try dropping the [] you don;'t need it.
Pattern p = Pattern.compile("wati");