这个正则表达式在 lex 中意味着什么

发布于 2024-12-19 04:04:02 字数 363 浏览 3 评论 0原文

我正在从 o'reilly 的一本书中学习 lex 和 yacc,并且遇到了一个 lex 示例,它处理命令、数字、字符串和换行符,忽略空格和注释。

我无法理解示例中的一个特定正则表达式:

\"[^\"\n]*\"

此表达式处理双引号中的文本。例如: "test regex" 将成功匹配,而测试正则表达式 不会匹配

维基百科<。 /a> 关于正则表达式的文章但是我还是不明白。

i am studying lex and yacc from an o'reilly book and i came across a lex example which handles commands, numbers, strings and new lines, ignoring white space and comments.

I am not able to understand one particular regular expression in the example:

\"[^\"\n]*\"

This expression handles text in double quotes. Eg: "test regex" will match successfully whereas test regex wont match.

I read the Wikipedia article on regular expressions but i still don't get it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那请放手 2024-12-26 04:04:02

双引号 (\"),除双引号或换行符之外的任何内容 ([^\"\n]) 0 次或多次 (*)、双引号 (\")。

double quote (\"), anything but double quote or linefeed ([^\"\n]) 0 or more times (*), double quote (\").

一城柳絮吹成雪 2024-12-26 04:04:02
\"

匹配起始引号(")。引号用 \ 转义,不会破坏正则表达式字符串。

[^\"\n]*

匹配除引号或行尾之外的任何内容。^ 表示不是,\n 是行尾,* 表示匹配 0 次或更多

\"

匹配最后一个引用

\"

match a starting quote("). quote is escaped with \ to not break the regex string.

[^\"\n]*

match anything except quote or end of line. ^ means not, \n is a end of line, * means match 0 times or more

\"

match last quote

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文