简体   繁体   English

正则表达式不带引号

[英]Regex quotation without quotation marks

I have a very nice regex, which selects quotations from text: 我有一个非常好的正则表达式,它从文本中选择引号:

(["']).+?\1

But I need a regex which selects quotations from text without the quotation marks. 但是我需要一个正则表达式,它从文本中选择不带引号的引号。

For example, I have: 例如,我有:

The whales comprise eight extant families: "Balaenopteridae" (the rorquals), "Balaenidae" (right whales), "Cetotheriidae" (the pygmy right whale), "Eschrichtiidae" (the gray whale), "Monodontidae" (belugas and narwhals), "Physeteridae" (the sperm whale), ... 鲸鱼由八个现存的科组成:“ Balaenopteridae”(ro科),“ Balaenidae”(右鲸),“ Cetotheriidae”(侏儒右鲸),“ Eschrichtiidae”(灰鲸),“ Monodontidae”(白uga和独角鲸) ,“ Physeteridae”(抹香鲸),...

I need to extract texts between quotation marks: 我需要在引号之间提取文本:

Balaenopteridae, Balaenidae, Cetotheriidae, ... 科,Bal科,C科,...

To extract texts between brackets I use regex: (?<=\\().+?(?=\\)) . 为了提取括号之间的文本,我使用了regex: (?<=\\().+?(?=\\)) It works great, but similar regex for quotation marks does not work. 它的效果很好,但是引号的类似正则表达式不起作用。 I want use the regex in php. 我想在php中使用正则表达式。

I tried to use this: 我试图用这个:

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

But it doesn't work. 但这是行不通的。 Can you help me? 你能帮助我吗?

(["'])(.+?)\1

然后只需获取第二组的值即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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