Memorandum Regular expression When there are multiple characters in the character string that you want to separate

Processing with regular expressions

・ Shortest match ・ Longest match

[Example sentence] String = "Free Throw Challenge_hoge-san _1st time"

For the above string ① I want to extract only free throw challenges (extract before the first underscore) ② I want to extract the number of times (extract after the last underscore)

①-> re.search ("(. *?) (? = _)", String) [0] → Free throw challenge extracted ②-> re.search ("([^ _] * $)", x) [0] → The first time is extracted

Recommended Posts

Memorandum Regular expression When there are multiple characters in the character string that you want to separate
When you want to replace multiple characters in a string without using regular expressions in python3 series
How to write a string when there are multiple lines in python
Software that saves the set character string to the clipboard when you click the [Python] button
[Linux] When you want to search for a specific character string from multiple files
How to turn the for statement when there are multiple values for one key in the dictionary
How to write when you want to put a number after the group number to be replaced with a regular expression in re.sub of Python
Handle CSV that contains the element you want to parse in the file name
When you want to update the chrome driver.
When you want to erase characters at once in terminal or line unit
When characters and voiced / semi-voiced sound marks are separated and you want to combine them
When the variable you want to superscript with matplotlib is two or more characters
[Memorandum] ① Get and save tweets ~ I want to identify the news tweets that are spread ~
When you want to plt.save in a for statement
Useful operation when you want to solve all problems in multiple programming languages with Codewars
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
How to quickly count the frequency of appearance of characters from a character string in Python?
[Python3] Code that can be used when you want to resize images in folder units
[Python] When you want to import and use your own package in the upper directory
When a character string of a certain series is in the Key of the dictionary, the character string is converted to the Value of the dictionary.
[Django] A memorandum when you want to communicate asynchronously [Python3]
Try to extract the keywords that are popular in COTOHA
When you want to use multiple versions of the same Python library (virtual environment using venv)
[Linux] I want to know the date when the user logged in
How to get all the possible values in a regular expression
Phenomenon that characters disappear when trying to enter one character without Enter
Regular expressions that are easy and solid to learn in Python
When you want to keep the Sphinx documentation theme as usual
[Python] When you want to use all variables in another file
When you want to save the result of the callback function somewhere
When you want to sort a multidimensional list by multiple lines
When you want to adjust the axis scale interval with APLpy
A note that you want to manually decorate the parameters passed in the Django template form item by item
I tried to summarize the methods that are often used when implementing basic algo in Quantx Factory
Python Note: When you want to know the attributes of an object
I want to batch convert the result of "string" .split () in Python
When you want to change the HTTP headers of Flask's test client
If you want to get multiple statistics with groupby in pandas v1
The eval () function that calculates a string as an expression in python
Memorandum of means when you want to make machine learning with 50 images
[Introduction to Python] Thorough explanation of the character string type used in Python!
[Python3] Code that can be used when you want to cut out an image in a specific size
How to deal with the problem that Japanese characters are garbled when outputting logs using JSON log formatter
[Python3] Code that can be used when you want to change the extension of an image at once