How can I extract two values ​​from a string like this using a regular expression?

advertisements

How can I get the value from the following strings using one regular expression?

/*##debug_string:value/##*/

or

/*##debug_string:1234/##*/

or

/*##debug_string:http://stackoverflow.com//##*/

The result should be

value
1234
http://stackoverflow.com/


Trying to read behind your pattern

re.findall("/\*##debug_string:(.*?)/##\*/", your_string)

Note that your variations cannot work because you didn't escape the *. In regular expressions, * mean a repetition of the previous character/group. If you really mean the * character, you must use \*.

import re
print re.findall("/\*##debug_string:(.*?)/##\*/", "/*##debug_string:value/##*/")
print re.findall("/\*##debug_string:(.*?)/##\*/", "/*##debug_string:1234/##*/")
print re.findall("/\*##debug_string:(.*?)/##\*/", "/*##debug_string:http://stackoverflow.com//##*/")

Executes as:

['value']
['1234']
['http://stackoverflow.com/']

EDIT: Ok I see that you can have a URL. I've amended the pattern to take it into account.