Oct-31-2016, 06:10 PM
(Oct-31-2016, 05:54 PM)snippsat Wrote:Same result. If I print(r.group(1)), I get the correct results, but when I assign .group(1) to r, I get the error message. Is there a bug or another step I may need to do for decoding or escaping asterisks??(Oct-31-2016, 05:31 PM)DBS Wrote: When I assign the variable to r as you have above, I get the error message, but if print r.group(1), I get the intended results??With the same code as i post?
Here as a script,tested Python 2 and 3.
import re s = '**string1;string2;string3**' r = re.search(r'\*\*(.*)\*\*', s) print(r.group(1)) #Now assign to variable r r = re.search(r'\*\*(.*)\*\*', s).group(1) print(r)
Output:string1;string2;string3 string1;string2;string3