【发布时间】:2010-03-21 13:41:20
【问题描述】:
我有一个测试列表,我正在尝试使用正则表达式捕获数据。
以下是文本格式示例:
(1) this is a sample string /(2) something strange /(3) another bit of text /(4) the last one/ something!/
我有一个正则表达式,目前可以正确捕捉到这一点,但我在使其在异常条件下工作时遇到了一些困难。
这是我的正则表达式
/\(?\d\d?\)([^\)]+)(\/|\z)/
不幸的是,有些数据包含这样的括号:
(1) this is a sample string (1998-1999) /(2) something strange (blah) /(3) another bit of text /(4) the last one/ something!/
子字符串 '(1998-1999)' 和 '(blah)' 让它失败了!
有人想试试这个吗? 谢谢 :D
【问题讨论】:
-
你没有说正则表达式应该捕获什么。
-
抱歉没有更具体。我现在正在查看大量答案(至少 2 个看起来正确)grin 我试图捕获我的示例捕获的文本(即英文文本减去编号)。