I’m looking for some help with a regular expression for a MYSQL query. I’m fairly new to expressions and have gotten myself thoroughly confused.
My database cell looks something like this
1314{{Here is some data}}1213{{More data here}}1112{{Data ahoy}}
And I’m trying to write an expression that’ll attempt to match the set of data, but only the data within the bracketed year.
For example, say that $year=1314 and $term=”ahoy”.
With the below REGEXP:
$year\{\{.* $term.*\}\}
It returns a match – because it’s matching the final “}}” of the 1112 prefixed dataset. I don’t want it to do this, but despite reading up on this greedy / negated business, I can’t get the syntax to work.
What would the best way to achieve what I’m after?
Try:
Where
[^}]*matches anything not a}so it will stop matching when it hits the first occurrence of}.*is greedy so it will match the last occurrence possible so.*\}\}matches the last set of}}to make it non-greedy you can use a?like.*?\}\}but I prefer using negation.