Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding regular expression

 
Anand Loni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic