This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes regarding regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "regarding regular expression" Watch "regarding regular expression" New topic
Author

regarding regular expression

Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hello,

I am working on RegX, my problem is I have built regular expression, but it has to include all characters, digits, special characters like *,%,# etc.
As \d stands for digit, \w stands for any char or digit. Is there anything that will include special charactes also ??

Hoping for reply.

Regards,
Anand


~ Anand,
SCJP 1.5, SCWCD 1.5
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707

I am working on RegX, my problem is I have built regular expression, but it has to include all characters, digits, special characters like *,%,# etc.
As \d stands for digit, \w stands for any char or digit. Is there anything that will include special charactes also ??


Pattern p1 = Pattern.compile("[\\w]|[^a-z0-9A-Z]");

It says, either any character a-z or A-Z or 0-9 (\w includes digits as well)OR "|" NOT "^" a-z, 0-9, A-Z. It will include all the special characters.
You can explicitely include special characters directly without any trouble like "#" , "%" , "@#" or something according to your need.

To opt for only special characters do like this:
"[^\\w\\s]"

cmbhatt
[ March 22, 2007: Message edited by: Chandra Bhatt ]

cmbhatt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding regular expression
 
Similar Threads
Regular expression + special characters
How to find if there is a number in a string using regular expressions.
Regular expression for allowing space, . , @ ,_ and , -
String replace
Regular expression