Regex whitespace and special characters
Posted
by
Sam R.
on Stack Overflow
See other posts from Stack Overflow
or by Sam R.
Published on 2012-11-03T04:44:38Z
Indexed on
2012/11/03
5:00 UTC
Read the original article
Hit count: 165
regex
I have this regular expression: [^\\s\"']+|\"([^\"]*)\"|'([^']*)'
which works for splitting a string by white spaces, and anything within a quotation is not delimited. However, I notice that if I put in a string that starts with ">" no matches are found. How would I correct this?
For example, if I enter ">> test 2". I want it to match to [>>, test, 2]
Note: using java to compile the regex, here is some code
Pattern pattern = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
Matcher matcher = pattern.matcher(SomeString);
while (matcher.find()){
String temp = matcher.group();
//... Do something ...
}
Thanks.
© Stack Overflow or respective owner