Removing letters from a string using Regular Expressions.

Very simple. but brain bending – All I wanted to do was remove a prefix from a string.

The prefix was always letters, and I only wanted the numerical suffix returned, so though, preg_replace was my best bet.

echo preg_replace("/[a-zA-Z]*/", '', '12345MystrING67890');

This returns :

1234567890

Perfect.

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.