In text i want to find structures like every thing till some text, but not match between some word.
Example in text:
Templates : You can add custom templates for your theme. Updated on 2010 look[124] end
Media RSS feed : Add the Cooliris Effect to your gallery Updated on 2011 look[124]
Role settings : Each gallery has a author Updated at 2010 ... look[124] end
AJAX based thumbnail generator : No more server Updated on 2010 look[124] end limitation during the batch process Copy/Move : Copy or move images between Updated on 2010 this look[124] galleries Sortable Albums : Create your own sets of images Updated on 2010 this look[124] end
Upload or pictures via a zip-file (Not in Safe-mode)
Watermark function : You can add a watermark image or text
...
I need to find “Updated .*[124] end” every match must start this “Update” and ends with “[number]” and word “end“. But some text looks very similar, but not ends with word “end“. This text must not mach. How to make it work?
I try to write
/Updated(.*?)\[.*?\]\send/msi
or
Updated(.*?)\[.*?\](?!Updated)\send
But this takes strings like:
Updated on 2011 look[124] Role settings : Each gallery has a author Updated at 2010 ... look[124] end
Updated on 2010 this look[124] galleries Sortable Albums : Create your own sets of images Updated on 2010 this look[124] end
How to write regex witch skips bad matches?
Thanks for your opinion.
I think this is what you were trying for with your second regex:
In other words, match
Updatedand look for the correspondingend. If you find anotherUpdatedfirst, you know you started at the wrong place, so abandon that match. I excludedendas well because that lets me match the words possessively (i.e., with*+); the regex never has to backtrack to find or (more importantly) eliminate a match.If you really have to specify the
look[nnn]part, this should do the trick:Add the
iflag for a case-insensitive match if you need to, but you don’t need themorsflags. If this seems overly complicated, it’s because I don’t know your data as well as you do. There’s a good chance this is all you really need: