Hello! Sit down, is it possible to create a regular expression that will exclude what is written in the template? It is necessary to find all the lines that ANY characters can have, EXCEPT English letters and numbers.

For example, preg_match("/[^az,AZ,0-9]/",$text) - will find all letters and numbers, but you need to, on the contrary, find anything except /[^az,AZ,0-9]/ Thanks in advance!

  • This example is already looking for everything except the selected ranges. ^ - negation of range. - Evgeny Borisov
  • The expression [^az,AZ,0-9] - on the contrary will not find all Latin letters and numbers. But if you remove the ^ symbol, then your pattern just finds only Latin letters and numbers. - Sasha Chernykh
  • And yes, the comma is not needed in the text, unless it is required by the task - Evgeny Borisov

1 answer 1

Commas separate the blocks do not need anything.
The last regular season ( /[^az,AZ,0-9]/ ) is almost correct, you just have to remove the commas:
/[^a-zA-Z\d]/ ( \d - short for 0-9 ).
See here.

UPDATE:

@ Sasha Chernyi suggested this option: ^[^A-Za-z0-9]+$ ( check ).
Finds strings that consist entirely of any characters except az\d .

  • Other, because the author "We need to find all the lines that ANY characters can have, EXCEPT English letters and numbers.", I suggest adding to the answer a template that resolves this task - ^[^A-Za-z0-9]+$ Is a demonstration , and / or more difficult, with the use of a negative lookahead — ^(?:(?![A-Za-z0-9]).)*$ Is a demonstration . Thank. - Sasha Chernykh
  • On the account of the first one, I agree, although maybe the string “something abstut” can be found in the TS, it will find two substrings (if you specify the flags). The task is not so well written to guess: which lines, completely whether they should fit the expression or part, how many of them, etc. They replied that they could. The author, apparently, this was enough. Second, why overload the kernel if it works anyway? PS Verification text puzzled :) - user207618