Remove all numbers just before a(delimiter)

$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.


Can I get my target result with your help?

Which “a”?

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?

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

1 Like

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?

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

Ah, Perl-Compatable Regular Expressions.

Thank you, m_hutely.

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:

1 Like

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

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.