Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / Regular Expression

Regular Expression

Regex https://regexr.com/3g1v7 matching .png

cheat sheet 線上教學: regexone

符合比對的話,會回傳 Match Object 否則回傳 None。

Python offers two different primitive operations based on regular expressions: match checks for a match only at the beginning of the string, while search checks for a match anywhere in the string (this is what Perl does by default).

# case_conversion/case_parse.py
import regex
upper = regex.compile(u'^[\p{Lu}]$')
sep = regex.compile(u'^[^\p{Ll}\p{Lu}\p{Nd}]$')
notsep = regex.compile(u'^[\p{Ll}\p{Lu}\p{Nd}]$')
valid_acronym = regex.compile(u'^[\p{Ll}\p{Lu}\p{Nd}]+$')