I would like to get “begin print x;;;” in python by re.search from this:
fv (x,y,z) begin print x;;; print y ;;; return x + y + z end;
I tried this: begin = re.search("begin .+;;;", line)
But this returns the following string: “begin print x;;; print y ;;;”
Any idea?
Repetition is greedy by default, meaning that it will match as many characters as possible. This results in the
.+passing right by the first;;;and matching the rest of the string up until the final;;;.To prevent this, change the
.+to.+?, which makes the repetition lazy (match as few characters as possible):