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'


Find me everything that starts with foo until bar


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


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


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



Delete everything up until foo:

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