舞台報幕


故事

你是一場國際研討會的舞台司儀。 你的工作是介紹講者、提醒他們時間到了,並主持 Q&A 時段。 你會事先拿到你所屬舞台的講者名單,並需要把他們變成主持卡。

由於這份名單遵循特定格式,你決定寫一個簡短程式,用正規表達式(regex)解析拿到的名單,並自動產生主持卡。

Note

這個練習不是在學正規表達式。 而是要學著在 $lang 中使用 regex。 提示中有現成的正規表達式,如果不想自己寫,可以直接使用。

你拿到的名單會包含每場演講的以下資訊:

  • 演講標題,
  • 講者姓名,
  • 講者代名詞(可選),
  • 講者所屬組織(可選),
  • 演講開始時間,
  • Q&A 時段開始時間(可選),
  • 以及演講結束時間。

完整條目的格式如下:

»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結束。

Note

由於名字可能包含一般連字號-,因此使用短破折號–來分隔講者與演講名稱。

你的程式應該為那場演講產生的主持卡長這樣:

- 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

這裡有幾點要注意:

  • 如果講者沒有提供所屬組織,主持卡中就省略。
  • 如果沒有提供 Q&A 時段時間,就表示講者選擇不回答問題。
  • 如果講者沒有指定代名詞,就改用講者的名字。 請注意,這樣縮短名字並不總是恰當,例如許多中文名字最好保留姓氏來縮短。 不過,在這個舞台上,縮短成名字的規則剛好對每位講者都適用。

任務

1. 寫出一個能擷取產生主持卡所需資訊的 regex

最簡單的方法是使用像 regex101 或 RegExr 這樣的 regex 建構工具。

!!! warning 請務必將 regex 引擎/方言設定為 $CHANGE_ME。

如果你剛接觸 regex,或是在建立一次擷取所有必要資訊的表達式時遇到困難,也可以定義幾個較小的表達式,分別擷取部分資訊。

2. 寫出一個接收一行資料並回傳所產生主持卡的函式

使用第一部分的表達式,實作一個函式:接收一行資料作為輸入,從中擷取資訊,並依照上述規格回傳所產生的主持卡。

測試案例

未來可能的測試案例應遵循以下準則:

  • 分隔符號必須明確。例如,演講標題不應包含»«,姓名不應包含逗號。
  • 測試案例應根據某些資訊是否為可選來排序。第一個案例應包含所有可能的資訊,下一個案例應排除一項可擷取的資訊,依此類推。
  • 使用[a-zA-Z]之類的模式來比對姓名、標題或組織的解法,不應該能通過測試。

實作

  • Julia(參考實作)