I have strings like this (some examples):
F7998FM3213/02F
J442554NM/05
K439459845/34D
I need to use PHP with preg_replace()
and regular expressions to delete all non-numeric characters in any string, after the forward-slash.
For example the codes above would look like this afterwards:
F7998FM3213/02
J442554NM/05
K439459845/34
To remove all \D
anywhere after a /
you could replace:
(?:/\K|\G(?!^))(\d*)\D+
with $1
. Like:
preg_replace(',(?:/\K|\G(?!^))(\d*)\D+,', '$1', $str);