aspose file tools*
The moose likes Java in General and the fly likes regex to detect slashes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "regex to detect slashes" Watch "regex to detect slashes" New topic
Author

regex to detect slashes

auvrm papu
Ranch Hand

Joined: Sep 01, 2005
Posts: 105


I need a simple regex in JAVA to return true or false based on the input.

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
What have you tried?
auvrm papu
Ranch Hand

Joined: Sep 01, 2005
Posts: 105
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

The starting and ending / are used in Perl regular expressions I think. In Java you don't need them; "[\\/]" will be enough.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
auvrm papu
Ranch Hand

Joined: Sep 01, 2005
Posts: 105
I tried that however, it detects only the "/" not the "\"

for example,



returns as valid string
auvrm papu
Ranch Hand

Joined: Sep 01, 2005
Posts: 105


actually worked

source:
http://www.regular-expressions.info/java.html

In literal Java strings the backslash is an escape character. The literal string "\\" is a single backslash. In regular expressions, the backslash is also an escape character. The regular expression \\ matches a single backslash. This regular expression as a Java string, becomes "\\\\". That's right: 4 backslashes to match a single one.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regex to detect slashes