A python regular expression, str and unicode that are sober and addictive

    """
When using a regular expression for a Japanese character string
String class of Japanese strings(str or unicode)And the regular expression string class needs to match
Example) re.match([If this is unicode], [This is also unicode])
    """

    str_japanese = '3 mana creature'
    unicode_japanese = u'Three mana creature'

    match = re.search('Mana', str_japanese)
    if match:
        print "Apply regular expression to str without u flag"

    match = re.search(u'Mana', str_japanese)
    if match:
        print "Assign the u flag to the regular expression for str"

    match = re.search('Mana', unicode_japanese)
    if match:
        print "Apply regular expression to unicode without u flag"

    match = re.search(u'Mana', unicode_japanese)
    if match:
        print "Assign the u flag to the regular expression for unicode"


    #By the way, the r flag is treated as str

    match = re.search(r'Mana', str_japanese)
    if match:
        print "Apply r flag to regular expression for str"

    match = re.search(r'Mana', unicode_japanese)
    if match:
        print "Apply r flag to regular expression for unicode"


    """
output(Only the part that matches properly is printed)

    >>>Apply regular expression to str without u flag
    >>>Assign the u flag to the regular expression for unicode
    >>>Apply r flag to regular expression for str
    """


Recommended Posts

A python regular expression, str and unicode that are sober and addictive
Python2 str / unicode and encode / decode
Regular expressions that are easy and solid to learn in Python
(Python) HTML reading and regular expression notes
[Python] A function that searches the entire string with a regular expression and retrieves all matching strings.
[Python] A game that uses regular expressions when, where, who, and what
str and unicode
A nice nimporter that connects nim and python
Make one repeating string with a Python regular expression.
A python lambda expression ...
python regular expression memo
Makes you think that Python regular expressions are great
Regular expression in Python
Regular expression in Python
A python regular expression, or a memo of a match object
Get the matched string with a regular expression and reuse it when replacing on Python3
Python error messages are specific and easy to understand "ga" (before that, a colon (:) and a semicolon (;))
Determine if a string is a time with a python regular expression
Python regular expression basics and tips to learn from scratch
Create code that outputs "A and pretending B" in python
How to write a metaclass that supports both python2 and python3
AtCoder ABC168 A case expression solved in Ruby and Python
[Python3] "A // B" and "math.floor (A / B)" are not always the same! ??
Python 處 處 regular expression Notes
Regular expression manipulation with Python
About Python and regular expressions
[Python3] I made a decorator that declares undefined functions and methods.
A memo that handles double-byte double quotes in Python regular expressions
I tried to make a regular expression of "amount" using Python
I tried to make a regular expression of "time" using Python
I tried to make a regular expression of "date" using Python
A quick guide to PyFlink that combines Apache Flink and Python
Verification of the theory that "Python and Swift are quite similar"
A python script that deletes ._DS_Store and ._ * files created on Mac
[Python] What are @classmethods and decorators?
String replacement with Python regular expression
This and that of python properties
a () and a.__ call__ () are not equivalent
[Python] return A [or / and] B
Get the number of searches with a regular expression. SeleniumBasic VBA Python
A summary of Python e-books that are useful for free-to-read data analysis
I hear that Matlab and Python loops are slow, but is that true?
A python program that resizes a video and turns it into an image
URL match checking and extraction with python regular expression Regex Full version
Solve with Ruby, Perl, Java and Python AtCoder ABC 047 C Regular Expression
The eval () function that calculates a string as an expression in python
Features of regular expression modules that I often use personally in Python