Question:
How to match special characters in java regex?
Lei
2007-06-28 23:58:50 UTC
How to match strng such as ""?

java String.matches() can match string "<" (only one character) using regex "<", "\074", "[\074]", etc, but if there are other characters in the string, it cannot be matched.
If grep, if using -E switch, "<" can be matched.
Four answers:
Floyd P
2007-06-29 00:08:41 UTC
Try doing

Pattern p = Pattern.compile("");

Then use the find() method on the Matcher object to check for a match.
heitschmidt
2016-11-16 10:41:06 UTC
Java Regex Special Characters
Zeus
2007-07-02 02:26:42 UTC
unlike regular expression in shell script, u need to escape twice in order to insert a special character:



example:

"\\@" - in java

\@ - in shell script



:)
anonymous
2016-10-03 11:00:39 UTC
The regex you prefer is /(H|h)ello.*(.*)/ (H|h)ello starts the a risk tournament with hi or hi .*     observed with the aid of any form of any character (     observed with the aid of the left parenthesis .*     observed with the aid of any form of any character )     observed with the aid of the wonderful parenthesis Any string with the development hi ....( ...) ... will try real with the regex given


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...