[英]Match word in PHP regex to not include
I want to fetch <FONT COLOR="#0000ff">(insert some text here)<\\/FONT>
with preg_match. 我想用preg_match获取<FONT COLOR="#0000ff">(insert some text here)<\\/FONT>
。 Lines similar to that are repeating and touching each other, so if I try something generic like <FONT COLOR="#0000ff">(?<NAME>+)<\\/FONT>
it'll fetch all of them as one cell. 类似于它的行重复并相互接触,所以如果我尝试像<FONT COLOR="#0000ff">(?<NAME>+)<\\/FONT>
这样的通用,它将把它们全部作为一个单元格获取。 So I threw on [^<]
to make it stop at the first less than it encountered, thus keeping it from including HTML and therefore being one cell... 所以我在[^<]
上使它停在第一个比它遇到的更少,从而使它不包含HTML,因此是一个单元格......
However, the text I'm fetching sometimes contains HTML that I want. 但是,我正在提取的文本有时包含我想要的HTML。 Is there a way to use [^]
with </F
? 有没有办法使用[^]
和</F
? My attempts at a negative look ahead did not work because it goes "yep, there's definitely a closing font tag on the end. Better not return anything." 我对前瞻性的尝试没有奏效,因为它是“是的,最后肯定会有一个结束的字体标记。最好不要返回任何东西。”
If I understand you correctly, you need a RegEx to perform non-greedy match. 如果我理解正确,您需要一个RegEx来执行非贪婪的匹配。 Eg, 例如,
If query string is: <x> abc </x> <x> def </x> <x> hig </x>
如果查询字符串为: <x> abc </x> <x> def </x> <x> hig </x>
Our RegEx is: /<x>(.*)<\\/x>/
我们的RegEx是:/ < /<x>(.*)<\\/x>/
(。*)/ /<x>(.*)<\\/x>/
Then a greedy match is performed and what is returned is the whole query string because it satisfies the RegEx. 然后执行贪婪的匹配,返回的是整个查询字符串,因为它满足RegEx。 To avoid it we use, non-greedy matching. 为了避免它,我们使用非贪婪的匹配。
New RegEx: /<x>(.*?)<\\/x>/
新RegEx:/ < /<x>(.*?)<\\/x>/
It should return all three tags with preg_match_all()
它应该使用preg_match_all()
返回所有三个标签
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.