你是一場國際研討會的舞台司儀。 你的工作是介紹講者、提醒他們時間到了,並主持 Q&A 時段。 你會事先拿到你所屬舞台的講者名單,並需要把他們變成主持卡。
由於這份名單遵循特定格式,你決定寫一個簡短程式,用正規表達式(regex)解析拿到的名單,並自動產生主持卡。
這個練習不是在學正規表達式。 而是要學著在 $lang 中使用 regex。 提示中有現成的正規表達式,如果不想自己寫,可以直接使用。
你拿到的名單會包含每場演講的以下資訊:
完整條目的格式如下:
»Speedrunning 101« – Sasha Duda Krall (they/them), from GDQU. Start: 13:00, Q&A: 13:20, End: 13:30
這裡的標題是Speedrunning 101,講者名叫Sasha Duda Krall,來自GDQU,使用they/them代名詞。
演講在13:00開始,13:20會開始 Q&A,整個時段在13:30結束。
由於名字可能包含一般連字號-,因此使用短破折號–來分隔講者與演講名稱。
你的程式應該為那場演講產生的主持卡長這樣:
- Our next speaker is Sasha Duda Krall, from GDQU
- Their talk is called »Speedrunning 101«
- They will answer your questions in the Q&A session at the end of the talk, starting at 13:20
13:00 - 13:20 - 13:30
整份名單可能長這樣:
»Speedrunning 101« – Sasha Duda Krall (they/them), from GDQU. Start: 13:00, Q&A: 13:20, End: 13:30
»How I learned to say Farewell« – Madeline (she/her). Start: 13:40, Q&A: 14:00, End: 14:05
»How To Find a Good Title For Your Conference Talk« – Vítězslav Kruse (he/him). Start: 14:15, End: 14:40
»Why Emoji Matter❣« – Ash van Amelsvoort, from the University of 🧬🧪⚛. Start: 14:50, Q&A: 15:05, End: 15:10
»Can dogs look up?« – Kira "k1ralli" Sørensen. Start: 20:50, Q&A: 21:05, End: 21:10
對應的主持卡如下:
- Our next speaker is Madeline
- Her talk is called »How I learned to say Farewell«
- She will answer your questions in the Q&A session at the end of the talk, starting at 14:00
13:40 - 14:00 - 14:05
- Our next speaker is Vítězslav Kruse
- His talk is called »How To Find a Good Title For Your Conference Talk«
- There will not be a Q&A session
14:15 - NO Q&A - 14:40
- Our next speaker is Ash van Amelsvoort, from the University of 🧬🧪⚛
- Ash's talk is called »Why Emoji Matter❣«
- Ash will answer your questions in the Q&A session at the end of the talk, starting at 15:05
14:50 - 15:05 - 15:10
- Our next speaker is Kira "k1ralli" Sørensen
- Kira's talk is called »Can dogs look up?«
- Kira will answer your questions in the Q&A session at the end of the talk, starting at 21:05
20:50 - 21:05 - 21:10
這裡有幾點要注意:
最簡單的方法是使用像 regex101 或 RegExr 這樣的 regex 建構工具。
!!! warning 請務必將 regex 引擎/方言設定為 $CHANGE_ME。
如果你剛接觸 regex,或是在建立一次擷取所有必要資訊的表達式時遇到困難,也可以定義幾個較小的表達式,分別擷取部分資訊。
使用第一部分的表達式,實作一個函式:接收一行資料作為輸入,從中擷取資訊,並依照上述規格回傳所產生的主持卡。
未來可能的測試案例應遵循以下準則:
»«,姓名不應包含逗號。[a-zA-Z]之類的模式來比對姓名、標題或組織的解法,不應該能通過測試。