S
S
spy452422018-05-17 11:32:58
PHP
spy45242, 2018-05-17 11:32:58

Why does the regular expression remove the letter B?

Actually I'm trying to remove extra characters from a string with such a regular expression:

preg_replace('/([:^~|@№$–=+*&%;\[\]<>()_—«»#\/]+)/i', "", $some);

But for some reason, all the letters B, both small and large, are deleted in the text.
What could be the problem?
I don’t understand, everything is tested normally on regexp. Could it be a coding issue?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nick Sdk, 2018-05-17
@spy45242

i checked the theory about the "unescaped hyphen"
if a hyphen is used in this place, _-«
then the regular expression haws like all characters from _ до «
if you look at the unicode character code "Underscore" _, we will see that it has a U+005Fserial number = 95
and "quotation mark", in its own turn U+00AB= 171
all Latin letters in lower case fall into this range,
and since you still have the "i" flag in the regular expression - case insensitivity, then this regular expression also includes Latin letters in Upper case
https://repl.it/ repls/SpryAzureAudit

A
Alexander Aksentiev, 2018-05-17
@Sanasol

6ff31712d88929c5181d5715ef99.png
No B is removed.
Added only /u for correct work with utf-8.

var_dump(preg_replace('/([:^~|@№$–=+*&%;\[\]<>()_—«»#\/]+)/iu', "", "Владимир владимирович #$#[email protected]%"));

B
Bogdan Karpov, 2018-05-17
@phpkoder

try this regular expression '[^a-zA-Z0-9а-яА-ЯёЁ]+?'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question