Re: [問題] 關於單選題問卷 該如何處裡
看板RegExp (正規表示式 Regular Expression)作者godspeedlee (妳,我可以)時間13年前 (2011/08/10 14:29)推噓0(0推 0噓 92→)留言92則, 3人參與討論串4/5 (看更多)
※ 引述《PurpleCrow (紫烏鴉)》之銘言:
: ※ 引述《godspeedlee (妳,我可以)》之銘言:
: : 分成兩次來作比較輕鬆:
: : 第一步: 將每個 Question 切割成單獨的區塊
: : \(Q\d+\)[\s\w]+(\(\d+\)\[[\s*]\][\s\w]+)+
: : 或
: : (?<=\(Q\d+\))(.*?)(?=\(Q\d+\))
: 這個式子會漏掉
: (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
謝謝,修正如下:
(?<=\(Q\d+\))(.*?)(?=\(Q\d+\)|\s*$)
: : 第二步: 對每個區塊個別進行搜尋
: : \(\d+\)\[\*\][\s\w]+
: (Q3) Question 3 依然無法排除 得
: (1)[*] Answer 1 for Question 3
: (3)[*] Answer 3 for Question 3
抱歉沒講清楚
我的意思是先切割成個別的問題(pattern1),然後再個
別去比對每個(Q#)裡面的答案(pattern2),假如成功比
對兩次(含)以上,那就是代表重複作答。
所以光靠 pattern2 沒辦法判斷出是否重複作答(抱歉
讓大家誤以為有這個意思)
假如要 pattern2 不用另外寫code去統計次數,下面這個 pattern
"也許"可行(不推薦):
^(?:\(\d\)\[\s*\][\s\w]+)*(\(\d\)\[\*\][\s\w]+)(?:\(\d\)\[\s*\][\s\w]+)*$
更變態一點,跟 pattern1 合體:
(非常不推薦)
\(Q\d+\)[\s\w]+(?:\(\d\)\[\s*\][\s\w]+)*(\(\d\)\[\*\][\s\w]+)(?:\(\d\)\[\s*\][\s\w]+)*(?=\(Q\d|$)
(無從得知重複作答跟沒有作答是哪些題目)
: : 當然,使用 regexp 常常會有一種衝動想一次解決 :P
: 這個題目跟一次解決或分次解決沒有關係
: 重點在於有複數個*的無效狀況無法排除
當然沒有關係,只是比較好作而已 ^_^"
--
http://godspeedlee.myweb.hinet.net/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.80.129.105
※ 編輯: godspeedlee 來自: 111.80.129.105 (08/10 14:42)
※ 編輯: godspeedlee 來自: 111.80.129.105 (08/10 14:47)
→
08/10 14:53, , 1F
08/10 14:53, 1F
→
08/10 16:14, , 2F
08/10 16:14, 2F
→
08/10 16:18, , 3F
08/10 16:18, 3F
→
08/10 16:18, , 4F
08/10 16:18, 4F
→
08/10 16:19, , 5F
08/10 16:19, 5F
→
08/10 16:22, , 6F
08/10 16:22, 6F
→
08/10 16:22, , 7F
08/10 16:22, 7F
→
08/10 16:23, , 8F
08/10 16:23, 8F
→
08/10 16:51, , 9F
08/10 16:51, 9F
→
08/10 16:51, , 10F
08/10 16:51, 10F
→
08/10 17:00, , 11F
08/10 17:00, 11F
→
08/10 17:01, , 12F
08/10 17:01, 12F
→
08/10 17:02, , 13F
08/10 17:02, 13F
→
08/10 17:07, , 14F
08/10 17:07, 14F
→
08/10 17:14, , 15F
08/10 17:14, 15F
→
08/10 17:15, , 16F
08/10 17:15, 16F
→
08/10 17:15, , 17F
08/10 17:15, 17F
→
08/10 18:10, , 18F
08/10 18:10, 18F
→
08/10 18:11, , 19F
08/10 18:11, 19F
→
08/10 18:12, , 20F
08/10 18:12, 20F
→
08/10 18:20, , 21F
08/10 18:20, 21F
→
08/10 20:13, , 22F
08/10 20:13, 22F
→
08/10 20:21, , 23F
08/10 20:21, 23F
→
08/10 20:22, , 24F
08/10 20:22, 24F
→
08/10 20:23, , 25F
08/10 20:23, 25F
→
08/10 20:23, , 26F
08/10 20:23, 26F
→
08/10 20:23, , 27F
08/10 20:23, 27F
→
08/10 20:32, , 28F
08/10 20:32, 28F
→
08/10 20:32, , 29F
08/10 20:32, 29F
→
08/10 20:33, , 30F
08/10 20:33, 30F
→
08/10 20:34, , 31F
08/10 20:34, 31F
→
08/10 20:39, , 32F
08/10 20:39, 32F
→
08/10 20:39, , 33F
08/10 20:39, 33F
→
08/10 20:43, , 34F
08/10 20:43, 34F
→
08/10 20:44, , 35F
08/10 20:44, 35F
→
08/10 22:02, , 36F
08/10 22:02, 36F
→
08/10 22:03, , 37F
08/10 22:03, 37F
→
08/10 22:03, , 38F
08/10 22:03, 38F
→
08/10 22:06, , 39F
08/10 22:06, 39F
→
08/10 22:08, , 40F
08/10 22:08, 40F
→
08/10 22:28, , 41F
08/10 22:28, 41F
→
08/10 22:28, , 42F
08/10 22:28, 42F
→
08/10 22:28, , 43F
08/10 22:28, 43F
→
08/10 22:29, , 44F
08/10 22:29, 44F
→
08/10 22:29, , 45F
08/10 22:29, 45F
→
08/10 22:29, , 46F
08/10 22:29, 46F
→
08/10 22:29, , 47F
08/10 22:29, 47F
→
08/10 22:30, , 48F
08/10 22:30, 48F
→
08/10 22:31, , 49F
08/10 22:31, 49F
→
08/10 22:31, , 50F
08/10 22:31, 50F
→
08/10 22:31, , 51F
08/10 22:31, 51F
→
08/10 22:32, , 52F
08/10 22:32, 52F
→
08/10 22:33, , 53F
08/10 22:33, 53F
→
08/10 22:33, , 54F
08/10 22:33, 54F
→
08/10 22:34, , 55F
08/10 22:34, 55F
→
08/10 22:35, , 56F
08/10 22:35, 56F
→
08/10 22:36, , 57F
08/10 22:36, 57F
→
08/10 22:36, , 58F
08/10 22:36, 58F
→
08/10 22:37, , 59F
08/10 22:37, 59F
→
08/10 22:37, , 60F
08/10 22:37, 60F
→
08/10 22:42, , 61F
08/10 22:42, 61F
→
08/10 22:42, , 62F
08/10 22:42, 62F
→
08/10 22:43, , 63F
08/10 22:43, 63F
→
08/10 22:44, , 64F
08/10 22:44, 64F
→
08/10 22:44, , 65F
08/10 22:44, 65F
→
08/10 22:45, , 66F
08/10 22:45, 66F
→
08/10 22:45, , 67F
08/10 22:45, 67F
→
08/10 22:47, , 68F
08/10 22:47, 68F
→
08/10 22:48, , 69F
08/10 22:48, 69F
→
08/10 22:49, , 70F
08/10 22:49, 70F
→
08/10 22:51, , 71F
08/10 22:51, 71F
→
08/10 22:51, , 72F
08/10 22:51, 72F
→
08/10 22:51, , 73F
08/10 22:51, 73F
→
08/10 22:51, , 74F
08/10 22:51, 74F
→
08/10 22:51, , 75F
08/10 22:51, 75F
→
08/10 22:52, , 76F
08/10 22:52, 76F
→
08/10 22:53, , 77F
08/10 22:53, 77F
→
08/10 22:53, , 78F
08/10 22:53, 78F
→
08/10 22:57, , 79F
08/10 22:57, 79F
→
08/10 22:58, , 80F
08/10 22:58, 80F
→
08/10 22:58, , 81F
08/10 22:58, 81F
→
08/10 22:58, , 82F
08/10 22:58, 82F
→
08/10 22:59, , 83F
08/10 22:59, 83F
→
08/11 00:30, , 84F
08/11 00:30, 84F
→
08/11 00:31, , 85F
08/11 00:31, 85F
→
08/11 00:31, , 86F
08/11 00:31, 86F
→
08/11 00:32, , 87F
08/11 00:32, 87F
→
08/11 00:32, , 88F
08/11 00:32, 88F
→
08/11 00:41, , 89F
08/11 00:41, 89F
→
08/11 00:41, , 90F
08/11 00:41, 90F
→
08/11 00:46, , 91F
08/11 00:46, 91F
→
08/11 00:48, , 92F
08/11 00:48, 92F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 5 篇):
RegExp 近期熱門文章
PTT數位生活區 即時熱門文章