Reputation: 4741
I have wrote a regex for split a strings by double-qoutes:
Pattern delimeter = Pattern.compile("\"");
How could I extend it for working with BOTH single and double qoutes?
I have tryied:
Pattern delimeter = Pattern.compile("\"'");
but this is not working right
Upvotes: 0
Views: 1050
Reputation: 41838
...But if you want to go crazy, there's...
[«‹»›„‚“‟‘‛”’"']
I realize that this is not exactly what you asked for, but it's something to consider when you're working in text from word processing software, where the writer might have used fancy quotes.
And that's not exhaustive: consider all the languages of the world and their ways of quoting text! There is a surprising variety of quotation marks out there.
String[] splitArray = subjectString.split("[«‹»›„‚“‟‘‛”’\"']");
For quotation fanatics only. :)
Upvotes: 0
Reputation: 56522
Two ways to do it :
Pattern delimeter = Pattern.compile("[\"']"); //Enclose them in brackets
Pattern delimeter = Pattern.compile("\"|'"); //But a "OR" between them.
Upvotes: 3