CDATA的正则表达式是什么 [英] What is the regex expression for CDATA

查看:251
本文介绍了CDATA的正则表达式是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个CDATA示例

Hi I have an example CDATA here

<![CDATA[asd[f]]]>

<tag1><![CDATA[asd[f]]]></tag1><tag2><![CDATA[asd[f]]]></tag2>

我拥有的CDATA正则表达式无法识别

The CDATA regex i have is not able to recognize this

"<![CDATA["([^\]]|"]"[^\]]|"]]"[^>])*"]]>"

这也不行

"<![CDATA["[^\]]*[\]]{2,}([^\]>][^\]]*[\]]{2,})*">"

请给我一个<![CDATA[asd[f]]]>的正则表达式,我需要在Lex/Flex中使用它

Will someone please give me a regex for <![CDATA[asd[f]]]>, I need to use it in Lex/Flex

:我已经回答了这个问题,请对我的回答进行投票,谢谢.

: I have answered this question, please vote on my answer, thanks.

推荐答案

这是解决方案.我们需要使用START STATE的原因是,<!CDATA[]]>之间的内容不会与其他REGEX匹配.

This is the solution. The reason we need to use a START STATE is so that what ever is between <!CDATA[ and ]]> does not get match against other REGEX.

%option noyywrap
%x CDATA

%%
"<![CDATA[" { BEGIN CDATA; printf("Entering CDATA\n"); }
<CDATA>([^\]]|\n)*|.    { printf("In CDATA: %s\n", yytext); }
<CDATA>"]]>" { 
    printf("End of CDATA\n");
    BEGIN INITIAL;
}

%%
main()
{
    yylex();
}

这篇关于CDATA的正则表达式是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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