Some Examples on Regex

For the topic, please refer to the Week 2 Thursday class. Example 1 is my own, and Example 2 is adapted from here and here to illustrate a more advanced pattern.

URL-1: https://www.debuggex.com/

URL-2: https://regex101.com/

URL-3: https://regexper.com/


Toy Regex Examples:

Example-1:

^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)\s+([A-Z]{3}-[A-Z0-9]{3})\s+(OK|WARN|ERR)\s+([A-Z]\d{2})\s+T=(-?\d+(?:\.\d+)?)C\s+V=(\d+(?:\.\d+)?)V$


2026-01-15T14:03:12Z MTR-AX7 ERR E42 T=83.4C V=11.92V

2026-01-15T14:03:15Z MTR-AX7 WARN W07 T=79C V=11.95V

2026/01/15 14:03:12Z MTR-AX7 ERR E42 T=83.4C V=11.92V

2026-01-15T14:03:12Z MTR-AX7 CRIT E42 T=83.4C V=11.92V

2026-01-15T14:03:12Z MTR-AX7 ERR E42 T=83.4 V=11.92V

2026-01-15T14:03:19Z PWR-9K1 OK O00 T=34.1C V=12V


Example-2:

^(?=.{1,254}$)(?=.{1,64}@)[A-Za-z0-9]+([._%+-][A-Za-z0-9]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,63}$


bob.smith+tag@sub.example.co.uk

a1_b2@dept-01.company.io

alice@example.com

bob.smith+promo@sub.example.co.uk

x_y-z@dept-01.company.io

name123@university.edu

@domain.com

alice@.com

alice..bob@example.com

alice@example

alice@example..com

alice@example.com.

alice@-example.com

alice@example-.com

alice example@example.com

@example.com

bob..smith@example.com

bob@-example.com 

bob@example..com 

bob@example