I have a document that looks like the following:
{{ link.description | default text }}
{{ link.description |default text}}
As you can see, it might or might not have spaces around “default text”. I want to extract the text “default text” using python’s re library with this code:
default = re.findall('|[ ]*(.*?)[ ]*}}', doc)
Unfortunately, I do not get the desired results with the above regular expression. I am trying to capture “default text” using (.*?), but it does not seem to be working.
In your regex
|[ ]*(.*?)[ ]*}}.1) You need to escape
|.2) Use
\s*forwhite-spaceoccurence.