How to remove numbers from a string with RegEx

Viewed 35491

I have a string like this:

" 23 PM"

I would like to remove 23 so I'm left with PM or (with space truncated) just PM.

Any suggestions?

Needs to be in PHP

9 Answers

trim() will allow a range of characters in the "character mask" parameter by using dot syntax.

Code: (Demo)

//              v--------literal spaces
trim(" 23 PM", ' 0..9')
//               ^^^^----all digits
// output: PM
Related