且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何提取引号字符串(双引号或单引号)

更新时间:2022-10-22 10:59:44

我想通了 - 使用反向引用。

 (['])(小于?Q>?+)\1 


Question 1:

For example,

     ... "ab'cd" ... 'ab"cd' ...

It should get ab'cd and ab"cd respectively. There may be many quoted strings.


Question 2:

And how to extract text <td>...</td> text from the following string?

<abc>text <td>...</td> text</abc>
<xyz>text <td>...</td> text</xyz>
<def>text <td>...</td> text</def>

abc, def, xyz may be nested in <td>.

I figured it out - using back reference.

(["'])(?<q>.+?)\1