How to fix this regular expression so that it does not return those characters that are specified at the end (characters / , * and пробел )
Here is the code:
preg_match_all("/[\/\*\s]*(.+)[\/\*\s]*/i", $str, $matches); var_dump($matches); If you pass the string */* str __#@33$*/%^& //* to this regular expression, you should return str __#@33$*/%^& , but return str __#@33$*/%^& //* .
These 4 //* symbols at the end should have disappeared, since the rule states:
/[/\*\s (). [/ \ * * s] * / i
I understand that .+ Captures everything, without checking that there should not be at the end //*
How to fix this expression? Also, these characters //* should not be ONLY at the end, they can be present in .+ , Therefore variants of the type [^\/\*\s]+ immediately disappear.
Also, if you make an expression like / /[\/\*\s]*(.+)[\/\*\s]+/i () str __#@33$*/%^& // /[\/\*\s]*(.+)[\/\*\s]+/i , the result will already be without an asterisk at the end: str __#@33$*/%^& // .
It turns out you can do it like this: / /[\/\*\s]*(.+)[\/\*\s]{4}/i / /[\/\*\s]*(.+)[\/\*\s]{4}/i str __#@33$*/%^& /[\/\*\s]*(.+)[\/\*\s]{4}/i and the result will be as needed: str __#@33$*/%^& , but the characters on the end may not be 4, but more or less, or it may not be at all.
Maybe something is connected with lazy and greedy checks? I do not understand anything.
.+captures everything that can capture. This is called greedy capture. To reduce greed, you must use a question mark..+?then it will only capture the first character that falls under the following expression - Mike/*in.+- user269067*// str1 str 2/**) - user269067