Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
制御文字や句読点にマッチする正規表現
import re
# ref: Regular Expression Cookbook p.26
text = """!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
aaa
bbb
"""
def match_literal_text(text):
pattern = "!\"#\$%&'\(\)\*\+,\-\./:;<=>\?@\[\\\]\^_`\{\|\}~"
return re.match(pattern, text)
if __name__ == '__main__':
m = match_literal_text(text)
print(m.group())
from match_literal_text import match_literal_text
def test_match_literal_text():
text = "!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"
m = match_literal_text(text)
assert m is not None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.