How to return all text before first underscore
Posted: 02 Nov 2012 10:19
Hi there, I'm trying to use regexreplace to get whatever text is before the first underscore. So, I want apple to be returned from apple_pear_banana_orange.
I have this:
but it returns apple_pear_banana and I can't figure out how to use the non-greedy ? to make it stop at the first underscore instead of the last. Cheers.
I have this:
Code: Select all
$a="<curbase>";
$b = regexreplace($a, "(.+)\_(.*)", "$1"),,1;
echo $b;but it returns apple_pear_banana and I can't figure out how to use the non-greedy ? to make it stop at the first underscore instead of the last. Cheers.