| | |
[regex help]Find EXACT characters in a String.
![]() |
•
•
Join Date: May 2009
Posts: 2
Reputation:
Solved Threads: 0
Ok, i got this so far ...
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
Java Syntax (Toggle Plain Text)
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Testing2 { public static void main(String[] args) { Pattern p = Pattern.compile("[wati]"); String text = "water"; Matcher m = p.matcher(text); if (m.find()) { System.out.print("Found !"); } } }
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
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
----------------------------------------------
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
•
•
Join Date: May 2009
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
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
----------------------------------------------
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
![]() |
Similar Threads
- Removing Characters from a String (C++)
- sorting characters in a string... help!!!! (C++)
- Capitalizing all characters of a string (C)
- Adding in escape characters into a string (C#)
- Count characters of a string. (C++)
- Counting all Non-blank Characters in a String (Java)
- Counting specific characters in a string (C)
- Removing characters from a string (C)
Other Threads in the Java Forum
- Previous Thread: JComboBox in JTable
- Next Thread: how to write java program which sholuld be able to send sms messages to mobile
| Thread Tools | Search this Thread |
add android api applet application applications array arrays automation bank binary bluetooth chat class clear client code codesnippet collections component converter database development dice digit eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jni jpanel julia linux list loop looping main map method methods mobile myregfun mysql netbeans newbie nonstatic openjavafx parameter pearl php print problem program programming project recursion repositories scanner scrollbar server set size sms sort sorting spamblocker sql sqlserver state storm string superclass swing swt text-file thread threads tree windows






