aspose file tools
The moose likes Java in General and the fly likes validation Special character using Regular Expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "validation Special character using Regular Expressions " Watch "validation Special character using Regular Expressions " New topic
Author

validation Special character using Regular Expressions

skumar nand
Greenhorn

Joined: Dec 18, 2008
Posts: 21
Hi All,

we are try to Special character using Regular Expressions but \ (backslash) not validating using below code



please help us to validate Special character including \ (backslash) .

Thanks in advance.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16680
    
  19


The backslash has special meaning to a regex AND to a java string. So, if you want the regex to not treat the backslash as special, and you want to use a string literal, then you need to escape twice.... giving you four backslashes.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
skumar nand
Greenhorn

Joined: Dec 18, 2008
Posts: 21

can you update the below Regular Expressions

Pattern pattern = Pattern.compile("[/,:<>!~@#$%^&()+=?()\"|!\\[#$-]");
skumar nand
Greenhorn

Joined: Dec 18, 2008
Posts: 21
Hi Henry,

Am not understand what ever you say.

can you provide me a example or change my Expressions according you.


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19214

Henry Wong wrote:giving you four backslashes.

Henry already gave you the answer.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: validation Special character using Regular Expressions
 
Similar Threads
Dangling meta character '*' near index 0 (java.util.regex.PatternSyntaxException)
regex and backslash..
split() method in String API
Regular expression: backslash inside bracket
jsp query regarding String concat add