※ 引述《chrisdar (克里斯)》之铭言:
: 现在我有一系列单选题问卷如下
: (Q1) Question 1
: (1)[ ] Answer 1 for Question 1
: (2)[ ] Answer 2 for Question 1
: (3)[*] Answer 3 for Question 1
: (4)[ ] Answer 4 for Question 1
: (Q2) Question 2
: (1)[ ] Answer 1 for Question 2
: (2)[ ] Answer 2 for Question 2
: (3)[ ] Answer 3 for Question 2
: (4)[ ] Answer 4 for Question 2
: (Q3) Question 3
: (1)[*] Answer 1 for Question 3
: (2)[ ] Answer 2 for Question 3
: (3)[*] Answer 3 for Question 3
: (4)[ ] Answer 4 for Question 3
: (Q4) Question 4
: (1)[*] Answer 1 for Question 4
: (2)[ ] Answer 2 for Question 4
: (3)[ ] Answer 3 for Question 4
: (4)[ ] Answer 4 for Question 4
: Pattern : \(Q(\d+)\).*?\((\d+)\)\[\*\]
: 现在问题出在
: 1. Q2 因为没有作答 导致把 Q3 的答案带到 Q2 去
: 2. Q3 重复作答也无法排除
: 可否提供一些思考方式或做法 谢谢
分成两次来作比较轻松:
第一步: 将每个 Question 切割成单独的区块
\(Q\d+\)[\s\w]+(\(\d+\)\[[\s*]\][\s\w]+)+
或
(?<=\(Q\d+\))(.*?)(?=\(Q\d+\))
第二步: 对每个区块个别进行搜寻
\(\d+\)\[\*\][\s\w]+
当然,使用 regexp 常常会有一种冲动想一次解决 :P