Powered by coANDco UK

Howto use regex (real life examples)

From How2s

Here you find some regular expressions examples from real life situatinons:

Find me every line that starts with 'sudo'

^sudo(.*?)

Find me everything that starts with foo until bar

^foo(.*?)bar

Find me every line that starts with 'sudo' until the end of the line

^sudo(.*?)$

Find me every line from beginning to end that has an occurence of 'sudo' (whole line)

^(.*?)sudo(.*?)$

Find me everything from the beginning of the line until the first [ character (TextMate)

^.*\[

PHP

Delete everything up until foo:

preg_replace("/^(.*?)foo/", "", $body);
Please check out our sponsor, thanks to whom How2s.org is FREE: