Regex - preg_replace php - Understading

I have the following code that I am trying to understand what exactly this code does, but after a few times I did not understand ...

OBS: This code was made a long time ago and worked to process some materials from the user, such as city, state, etc.

preg_replace('/\A[\w\.\-\+]+\z/', '', $anyString) 

What I already know:

\A = match at the beginning of input

\w = Match any word

\. , \- , \+ \. , \- , \+ = Matches the symbol., And +

\z = Matches the end of a line

Any help would be appreciated, Thanks

+4
source share
1 answer
 \A - start at the beginning [ - match any of the following: \w - a word character (az, AZ, 0-9, underscore) \. - a dot \- - a dash \+ - a plus ] + - at least one time, but possibly more. \z - end at the end 

Thus, the entire line, from beginning to end, must consist of letters, numbers, underscores, periods, dashes, or pluses and must contain at least one character.

If so, replace it with an empty string (I'm curious why this is useful).

+5
source

All Articles