The bold text is what I’m trying to capture “the yard“.
One boat in here. (in the yard)
One boat in here. in the yard
My regex captures “here. (in the yard”, it gets caught on the first “in”, but im trying to get it to only catch on the last appearance of “in”.
My current regex is
\s\(?in([^\)]+)\)?$
If you know the solution please explain the regex, I would like to understand how it works.
\sFind a space\(?Zero or one (i.e., optional) open parenthesisinLiteral i followed by literal n[^\)]+CAPTURE: One or more characters, none of which are)(and maybe\(not sure about this bit))\)?Optional close parenthesis$End of lineThis clearly matches the first string, with
here. (in the yardbeing captured.fix:
The
.*causes the regex engine to first find the end of the string. It then backtracks from there to the last in.