File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check special characters in java code using Java.util.regex package

 
java code code java
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even i need the same function to check special character in string
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to our JiG(B) forum.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"java code java code", please check your private messages. You can see them by clicking My Private Messages.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vikalp Singh:
even i need the same function to check special character in string


Then Ken's answer should help you.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic