问题描述
(\ [(C | C)=)?(#([A-FA-F0-9] {1,2}){ 3})\(*)\ [/(C |。C)\]
我想这个表达式匹配类似的文字:这是[C = FFFFFF]白色文字[/ C]和[C =#000]黑色文本[/ C]。
它做匹配只身一BB代码,但如果有后,彼此之间多(比如上例中),它会创建两个BB-代码序列的比赛(1场)。 (从[C = FFFFFF] WH ...到... CK文字[/ C])
这是怎么回事?此外,如何让我的点(。)包括换行符在C#中?
如果你不关心嵌套的标签,你可以这样做:
(\ [[CC] =)(#(? [A-FA-F0-9] {3}){1,2})\(*)\ [/ [CC] \]
// ^ - ?懒惰匹配
如果你想处理嵌套标签与正则表达式,检查的。
(\[(c|C)=)(#?([a-fA-F0-9]{1,2}){3})\](.*)\[/(c|C)\]
I want this expression to match text like: "This is [c=FFFFFF]white text[/c] and [C=#000]black text[/C]."
It do match one BB-code alone, but if there are more after each other (like in the example), it will create a match (1 match) of both BB-code-sequences. (from [c=FFFFFF]wh... to ...ck text[/C])
Why is this happening? Also, how do I make the dot (.) include newlines in C#?
If you don't care about nested tags, you can do that :
(\[[cC]=)(#?([a-fA-F0-9]{3}){1,2})\](.*?)\[/[cC]\]
// ^- lazy match
If you want to handle nested tags with regex, check this article on code project.
这篇关于正则表达式匹配太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!