如何提取引号字符串(双引号或单引号) [英] How to extract the string in the quotes (either double quotes or single quotes)

查看:1108
本文介绍了如何提取引号字符串(双引号或单引号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问1:



例如,

 
......ab'cd......ABCD......

这应该得到 ab'cd 分别 ABCD 。 。可能有许多带引号的字符串






问题2:



和如何提取文字< TD> ...< / TD>文字从以下字符串?





<预类=郎HTML prettyprint-覆盖> < ABC>文字< TD> .. < / TD>文字< / ABC>
< XYZ>文字< TD> ...< / TD>文字< / XYZ>
< D​​EF>文字< TD> ...< / TD>文字< / DEF>



ABC,DEF,XYZ可以嵌套在< TD>


解决方案

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

 (['])(小于?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

这篇关于如何提取引号字符串(双引号或单引号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆