| Author |
How to check special characters in java code using Java.util.regex package
|
java code code java
Greenhorn
Joined: May 11, 2006
Posts: 1
|
|
String guid="first_Name;Last_Name"; Pattern p5 = Pattern.compile("\\p{Punct}"); Matcher m5 =p5.matcher(guid); boolean test=m5.matches(); I want to find out the weather any speacial characters are there in the String guid using regex. but above code is always returning false. pls suggest.
|
 |
Ken Blair
Ranch Hand
Joined: Jul 15, 2003
Posts: 1078
|
|
Read the documentation:
matches public boolean matches() Attempts to match the entire region against the pattern. If the match succeeds then more information can be obtained via the start, end, and group methods. Returns: true if, and only if, the entire region sequence matches this matcher's pattern
Does the entire region match your expression? You should be using find instead.
|
 |
Vikalp Singh
Ranch Hand
Joined: Dec 29, 2002
Posts: 50
|
|
|
even i need the same function to check special character in string
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8141
|
|
|
Moving this to our JiG(B) forum.
|
[My Blog] [JavaRanch Journal]
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
|
"java code java code", please check your private messages. You can see them by clicking My Private Messages.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Vikalp Singh: even i need the same function to check special character in string
Then Ken's answer should help you.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: How to check special characters in java code using Java.util.regex package
|
|
|