Remove all numbers just before a(delimiter)


#1
$myVar='ra123arf456rq578a9b';
$myVar1=preg_replace('/\d+/', '', $myVa

I have $myVar like the above.
The result of $myVar1 wil be “raarfrqab”

I like to remove all numbers which are just before “a”.
The follwoing is my target result.

raarf456rqa9b

Can I get my target result with your help?


#2

Which “a”?


#3

Well, you want to replace any digits directly before the character a.
So, we know digits have to be in the preg_replace and a has to be in there.
You already have digits (\d), but where is the a? Where do you suppose it should go?


#5

Actually, the result he wants is preg_replace("/\d+a/","a",$myVar);


#7

Thank you it works fine.

By the way,
I think “reg” in preg means regular expresssion.
I like to know what “p” in preg means?
What does it stand for?


#8

Perl.
PHP implements PCRE, or “Perl-Compatable Regular Expressions”. The function prefix for this group of functions is preg_


#9

Ah, Perl-Compatable Regular Expressions.

Thank you, m_hutely.


#10

I know that, I just wanted to see if he could get there on his own.

Give a man a fish and all that :slight_smile:


#11

That post… was in reference to a post that has since disappeared. lol.