Regex whitespace and special characters
- by Sam R.
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.