开发者

regular expression: quotes within quotes

I need to do following type of regular expression match

E.g if i have a string - some "This is "sample" data" example

I want to extract "This is "sample" data" out of the above string. Could please give me a regular expression which can return me desired results

More Details

I have a string as - keyword = "This is "blood" sample" AND name = "some text". I need to extract keyword = "This is "blood" sample" name = "s开发者_StackOverflow中文版ome text" out of it as two separate strings.

Could you please suggest a regular expression for this kind of thing

I used (keywords|name|title) = (.*?(\\\".*\\\").*?) as regular expression and it does not work as expected. It returns me the whole string as it.

Thanks in advance.


Not quite sure what you're after, so I'll fill in the gaps by guessing.

Pattern p = Pattern.compile(".*?(\\\".*\\\").*?");
Matcher m = p.matcher("some \"This is \"sample\" data\" example");

if (m.matches())
    System.out.println(m.group(1));

Output:

"This is "sample" data"

Some remarks:

  • What should be matched in a b "c d "e f "g h" i j" k l" m n?
  • What should be matched in a "b" c"?
  • If you want to treat " and " as opening and closing parenthesis, regular expressions are not for you.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜