I’m trying to make a regex which gets the part between two other things using PHP.
I have:
RANDOMSTUFFpart1CONTENTpart2RANDOMSTUFF2
So I want to extract CONTENT from between part1 and part2.
Is there a generic regex expression that I can use, where I just add in code for part1 and part2 and it will work?
Something like:
$part1='';
$part2='';
$string='RANDOMSTUFFpart1CONTENTpart2RANDOMSTUFF2';
$regexthing=...
I don’t know if Dimitri will return to edit his answer, so I will put the corrected solution here:
$part1 = 'part1';
$part2 = 'part2';
$string = 'RANDOMSTUFFpart1CONTENTpart2RANDOMSTUFF2';
$pattern = '/' . $part1 . '(.*?)' . $part2 . '/';
preg_match($pattern, $string, $match);
EDIT: Yes, if nothing may be between two parts use (.*?)