Only Match Words That Are Outside of Certain Tags (Regex

I am working on writing my own BBCode parser. I am VERY new to writing Regexs.

I am trying to make it so that my regex would match all tags, except if they are inside of a code or quote tag. Here is what I mean:

[b] This text will be bolded [/b]

[code][b] This text will NOT be bolded [/b][/code]
[quote][b] This text will NOT be bolded [/b][/quote]

Problem is it is matching the text that SHOULD NOT be bolded...

Here is my regex:

/((?![code]) [b](.*)[/b] (?!=/code]))/gi

And you can find a working example here: https://regex101.com/r/oI3mN8/2

So my question is, how can I make it grab the correct stuff?

PS how can I make it grab each chunk? Right now it is grabbing the first and last. Example:

[b] This text should be bolded [/b]
This text should not be bolded, but it still is.
[b] This text should be bolded again [/b]

It for some reason is just grabbing the first and last tags, why?

链接地址: http://www.djcxy.com/p/29886.html

上一篇: 最适合PHP的XML解析器

下一篇: 只匹配某些标签之外的单词(正则表达式)