Regex - preg_replace php - Understading

expression, php, preg-replace, regex

Solution

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

So the entire string, from start to end, must be composed of letters, digits, underscores, dots, dashes or pluses and must be at least one character long.

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

Problem

I have the following code that I'm trying to understand what exactly this code does, but after several time I didn't figure out... OBS: This code was made a long time ago and was working for treat some inputs from user, such as city, state and etc. ``` preg_replace('/\A[\w\.\-\+]+\z/', '', $anyString) ``` What I already know: `\A` = Match at the beginning of the input `\w` = Match any word `\. , \- , \+` = Match the character . , and + `\z` = Match the end of the string Any help would be appreciated, Thanks

Original source