简体   繁体   中英

Regex for single or double-quote delimeter

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

Two ways to do it :

 Pattern delimeter = Pattern.compile("[\"']"); //Enclose them in brackets
 Pattern delimeter = Pattern.compile("\"|'"); //But a "OR" between them.

...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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM