Actually, here is the regular expression that I got:

\/[a-zA-Zа-яА-Я0-9]{1}[-a-zA-Zа-яА-Я0-9\.]{1,}((\?[а-яa-zА-ЯA-Z]{1,}=[0-9]{1,})|(\#[а-яa-zА-ЯA-Z]{1,})|()) 

Idea, should skip only such lines

  • /blah blah blah
  • / blah blabla
  • / blablabla # blablabla
  • / blablabbala? yvapwap = 123409008098

The problem is that it skips this:

  • / blablabbala? yvapwap =

I think that there should be a logical one before the first parenthesis. How to set a logical and?

    1 answer 1

    Add start ( ^ ) and end of line ( $ ) operators and correct the pattern as follows:

     /^\/[a-zа-яё0-9][-a-zа-яё0-9.]+(?:\?[а-яa-zё]+=[0-9]+|#[а-яa-zё]+)?$/iu 

    See the demo

    Using the i modifier, you can not repeat the letters in the opposite case, and the u modifier allows you to process the pattern and strings in Unicode.

    Notice that {1,} = + (so shorter).

    • For some reason did not immediately guess, thanks. - Ghost