davus
November 2, 2012, 1:25am
1
So let's say I have these given variables:
string $header = "start"; string $footer = "end";
string $sentance = "start a bunch of text end";
I'm trying to match everything between the $header and $footer variables in the $sentance string. I've been scouring the web trying to find an answer to no avail. Any help is appreciated, thanks!
joojaa
November 2, 2012, 2:03am
2
use the regular expression:
$header+".*"+$footer
Then substring
davus
November 2, 2012, 12:47pm
3
ahh perfect... thanks a bunch!
joojaa
November 3, 2012, 6:14pm
4
in mel
substitute "bar hum hum foo" "s/bar(.*)foo/$1/";
in python
import re re.match("bar(.*)foo","bar hum hum foo").group(1)
now python also knows to be not greedy with
re.match("bar(.*?)foo","bar hum hum foo hum hum foo").group(1)