I'm looking to "trim" non-alphanumerics from a string, similar to how trim()
works with whitespace.
Help me convert #str|ng#
to str|ng
.
I can remove trailing non-alphanumerics with:
$string = preg_replace('/W+$/', '', $string); // converts `#str|ng#` to `#str|ng`
And leading with:
$string = preg_replace('/^W+/', '', $string); // converts `#str|ng#` to `str|ng#`
But how can I accomplish both at the same time?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…