I would like to improve my preg_replace regex. This is to clean a features list.
I want allow for the begining of each line:
- alphanumeric characters
- == and alphanumeric characters
- -- alphanumeric characters
- ++ alphanumeric characters
- ** alphanumeric characters
my regex:
$features = "
== Category one
→ feature 1
++ feature 2
-- feature 3
==-
! feature 4
% feature 5";
preg_replace('/' .
'^[^[:alnum:]]{0,}(==-.*)$' . '|' . // ==-
'^[^[:alnum:]]{0,}([\+|\-|\*|\=]{2}.*)$' . '|' . // ==
'^[^[:alnum:]]{0,}(.*)$' . // abc
'/mu', '$1$2$3',
$features);
Dirty features:
- == Category one
- → feature 1
- ++ feature 2
- -- feature 3
- ==-
- ! feature 4
- % feature 5
Clean:
- == Category one
- feature 1
- ++ feature 2
- -- feature 3
- ==-
- feature 4
- feature 5
It works, but i think there is a better way ... Thanks