为什么正则表达式不能使用关键字而不是字符? [英] Why can't Regular Expressions use keywords instead of characters?
问题描述
好吧,我几乎不了解RegEx基础知识,但是为什么他们不能将其设计为使用关键字(例如SQL)而不是一些神秘的通配符和符号?
Okay, I barely understand RegEx basics, but why couldn't they design it to use keywords (like SQL) instead of some cryptic wildcard characters and symbols?
由于RegEx是在运行时解释/解析的,因此它是否具有性能? (未编译)
Is it for performance since the RegEx is interpreted/parsed at runtime? (not compiled)
还是为了提高写作速度?考虑到当您学习一些简单"字符组合时,键入1个字符而不是关键字会变得更容易吗?
Or maybe for speed of writing? Considering that when you learn some "simple" character combinations it becomes easier to type 1 character instead of a keyword?
推荐答案
您真的想要这个吗?
Pattern findGamesPattern = Pattern.With.Literal(@"<div")
.WhiteSpace.Repeat.ZeroOrMore
.Literal(@"class=""game""").WhiteSpace.Repeat.ZeroOrMore.Literal(@"id=""")
.NamedGroup("gameId", Pattern.With.Digit.Repeat.OneOrMore)
.Literal(@"-game""")
.NamedGroup("content", Pattern.With.Anything.Repeat.Lazy.ZeroOrMore)
.Literal(@"<!--gameStatus")
.WhiteSpace.Repeat.ZeroOrMore.Literal("=").WhiteSpace.Repeat.ZeroOrMore
.NamedGroup("gameState", Pattern.With.Digit.Repeat.OneOrMore)
.Literal("-->");
好,但是这是您的葬礼,伙计.
在此处下载执行此操作的库:
http://flimflan.com/blog/ReadableRegularExpressions.aspx
Download the library that does this here:
http://flimflan.com/blog/ReadableRegularExpressions.aspx
这篇关于为什么正则表达式不能使用关键字而不是字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!