这个正则表达式在 lex 中意味着什么
我正在从 o'reilly 的一本书中学习 lex 和 yacc,并且遇到了一个 lex 示例,它处理命令、数字、字符串和换行符,忽略空格和注释。
我无法理解示例中的一个特定正则表达式:
\"[^\"\n]*\"
此表达式处理双引号中的文本。例如: "test regex" 将成功匹配,而测试正则表达式 不会匹配
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
双引号
(\"
),除双引号或换行符之外的任何内容
([^\"\n]
) 0 次或多次 (*
)、双引号
(\"
)。double quote
(\"
),anything but double quote or linefeed
([^\"\n]
) 0 or more times (*
),double quote
(\"
).匹配起始引号(")。引号用 \ 转义,不会破坏正则表达式字符串。
匹配除引号或行尾之外的任何内容。^ 表示不是,\n 是行尾,* 表示匹配 0 次或更多
匹配最后一个引用
match a starting quote("). quote is escaped with \ to not break the regex string.
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