Chris Tate-Davies

An archive of helpful tit bits of information for development, and probably some stuff that is incomplete, wrong or boring…

REGEX – Remove Letters from string

Posted on | March 18, 2010 | No Comments

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.

 

Comments

Leave a Reply