[PYTHON] How to get all the possible values in a regular expression

Thing you want to do

input

http://xxx/abc[x-z]/image(9|10|11).png

Value you want to get

http://xxx/abcx/image9.png
http://xxx/abcy/image9.png
http://xxx/abcz/image9.png
http://xxx/abcx/image10.png
http://xxx/abcy/image10.png
http://xxx/abcz/image10.png
http://xxx/abcx/image11.png
http://xxx/abcy/image11.png
http://xxx/abcz/image11.png

manner

sample.py


import sre_yield

if __name__ == '__main__':
    regex = r'http://xxx/abc[x-z]/image(9|10|11)\.png'
    urllist = list(sre_yield.AllStrings(regex))
    print(urllist)

Execution result


['http://xxx/abcx/image9.png', 'http://xxx/abcy/image9.png', 'http://xxx/abcz/image9.png', 'http://xxx/abcx/image10.png', 'http://xxx/abcy/image10.png', 'http://xxx/abcz/image10.png', 'http://xxx/abcx/image11.png', 'http://xxx/abcy/image11.png', 'http://xxx/abcz/image11.png']

Recommended Posts

How to get all the possible values in a regular expression
How to get all the keys and values in the dictionary
How to get the last (last) value in a list in Python
How to get a stacktrace in python
How to get the vertex coordinates of a feature in ArcPy
How to write regular expression patterns in Linux
How to get the files in the [Python] folder
How to get the variable name itself in python
How to get the number of digits in Python
[Python] How to output the list values in order
How to get a list of files in the same directory with python
[Ruby] How to replace only a part of the string matched by the regular expression?
How to use the __call__ method in a Python class
I tried "How to get a method decorated in Python"
How to generate a query using the IN operator in Django
How to get a list of built-in exceptions in python
[Shell] How to get the remote default branch in Git
How to get a quadratic array of squares in a spiral!
How to get the Python version
How to determine the existence of a selenium element in Python
How to check the memory size of a variable in Python
How to get a string from a command line argument in python
[Python] How to get & change rows / columns / values from a table.
How to use the asterisk (*) in Python. Maybe this is all? ..
[Introduction to Python] How to use the in operator in a for statement?
How to check the memory size of a dictionary in Python
How to combine all CSVs in a folder into one CSV
Create a function to get the contents of the database in Go
Get the top nth values in Pandas
How to get colored output to the console
How to handle consecutive values in MySQL
How to use regular expressions in Python
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
Get the number of searches with a regular expression. SeleniumBasic VBA Python
How to get a specific column name and index name in pandas DataFrame
How to get the date and time difference in seconds with python
How to specify a .ui file in the dialog / widget GUI in PySide
[Linux] Command to get a list of commands executed in the past
How to get a value from a parameter store in lambda (using python)
How to get a namespaced view name from a URL (path_info) in Django
How to sort by specifying a column in the Python Numpy array.
How to assign multiple values to the Matplotlib colorbar
How to calculate the volatility of a brand
How to use the C library in Python
How to clear tuples in a list (Python)
How to embed a variable in a python string
Get the caller of a function in Python
How to get results from id in Celery
How to create a JSON file in Python
How to get help in an interactive shell
How to implement a gradient picker in Houdini
Get only the subclass elements in a list
How to notify a Discord channel in Python
[Python] How to draw a histogram in Matplotlib
How to create a Rest Api in Django
How to write a named tuple document in 2020
How to count numbers in a specific range
Use pygogo to get the log in json.
How to read a file in a different directory
Create a command to get the work log
How to Mock a Public function in Pytest