[regex help]Find EXACT characters in a String.

Reply

Join Date: May 2009
Posts: 2
Reputation: username7260 is an unknown quantity at this point 
Solved Threads: 0
username7260 username7260 is offline Offline
Newbie Poster

[regex help]Find EXACT characters in a String.

 
0
  #1
May 20th, 2009
Ok, i got this so far ...

  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Testing2 {
  5.  
  6. public static void main(String[] args) {
  7. Pattern p = Pattern.compile("[wati]");
  8. String text = "water";
  9. Matcher m = p.matcher(text);
  10. if (m.find()) {
  11. System.out.print("Found !");
  12. }
  13. }
  14. }

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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,386
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: [regex help]Find EXACT characters in a String.

 
0
  #2
May 20th, 2009
Do you want to match the String "wati", or do you want to match a String that contains a w or an a or a t or an i (which is what your pattern says now)? Or do you want to match a String that contains all of those characters regardless of order or amount?
Last edited by masijade; May 20th, 2009 at 12:58 pm.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 2
Reputation: username7260 is an unknown quantity at this point 
Solved Threads: 0
username7260 username7260 is offline Offline
Newbie Poster

Re: [regex help]Find EXACT characters in a String.

 
0
  #3
May 20th, 2009
thanks for your answer !!

i want to match a String that contains all of those characters regardless of order or amount BUT if a character is not in the string it should be NO matches ...

for example :

t match "water"
ret match "water"
retaw match "water"
wret match "water"
BUT
'i' DOESNT match "water" because 'i' is not in the string "water"
watzer DOESNT match "water" because 'z' is not in the string "water"

that is how the regex should work for what i need ...

is kinda hard to explain, hope you understand, and thanks again.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,386
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: [regex help]Find EXACT characters in a String.

 
0
  #4
May 20th, 2009
I have now given you a full answer on Sun's forums.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC