How to remove numbers from a string with RegEx

前端 未结 8 618
花落未央
花落未央 2020-12-06 04:56

I have a string like this:

\" 23 PM\"

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

相关标签:
8条回答
  • 2020-12-06 05:53

    Can also use str_replace, which is often the faster alternative to RegEx.

    str_replace(array(1,2,3,4,5,6,7,8,9,0,' '),'', ' 23 PM');
    // or
    str_replace(str_split(' 0123456789'), '', ' 23 PM');
    

    which would replace any number 0-9 and the space from the string, regardless of position.

    0 讨论(0)
  • 2020-12-06 05:56
    echo trim(str_replace(range(0,9),'',' 23 PM'));
    
    0 讨论(0)
提交回复
热议问题