作者abliou (Art of Life)
看板Perl
标题[问题] (?(condition)yes-pattern|no-pattern) REGEX的问题
时间Mon Dec 17 17:02:48 2007
这是在perldoc中perlre中的一段...
(?(condition)yes-pattern|no-pattern)
(?(condition)yes-pattern)
WARNING: This extended regular expression feature is considered highly
experimental, and may be changed or deleted without notice.
Conditional expression. (condition) should be either an integer in
parentheses (which is valid if the corresponding pair of parentheses
matched), or look-ahead/look-behind/evaluate zero-width assertion.
For example:
m{ ( \( )?
[^()]+
(?(1) \) )
}xmatches a chunk of non-parentheses, possibly included in
parentheses themselves.
小弟看了很久,却还是不明白condition中的意义还有pattern的意义....
在programing perl第162页有提到一下...
此外让人困惑的是另一个语法
(??{...})..在同一页也有提到..
但是却没有详细说明...
将它的example贴到perl上也确实能运行...
不知道版上的高手们能不能指点小弟一下...到底这几个regex的用途和写法是如何?
小弟十分感激!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.123.222.163