【发布时间】:2010-08-29 20:20:18
【问题描述】:
这是一个整洁的、有据可查的正则表达式,易于理解、维护和修改。
text = text.replace(/
( // Wrap whole match in $1
(
^[ \t]*>[ \t]? // '>' at the start of a line
.+\n // rest of the first line
(.+\n)* // subsequent consecutive lines
\n* // blanks
)+
)
/gm,
但是你如何处理这些?
text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
是否有某种beautifier 可以理解并描述其功能?
【问题讨论】:
-
也许stackoverflow.com/questions/32282/regex-testing-tools 中的一些工具会有所帮助。
-
我都不做。我总是使用 6-10 行代码和 explode/join/strstr/substr (PHP) 来代替。更易于理解、维护甚至编写。
-
由于添加了空格,并非所有支持正则表达式的语言或库都能像您的示例一样干净利落。
标签: regex maintainability