I have a python code like below: My question is why the matched variable is [\' \']? (I used the regex in regexpal.com, it can find the right result |Name=A. Johnson | there)
You'll want (.*?)
, not (.)*?
—the latter (what you have) will only capture a single character, even if it consumes more than a single one. A capture group will only be returned once even if the group itself has a repeat; so the latter captures a single character (.)
despite its repeat.
If you move the repeat into the capture group with (.*?)
, you'll get more than a single character in the return.