regexcyrillic

Regex to find at least one cyrillic character


I want to find one or more cyrillic characters(а-я) within a string. So far i manage to find the character wherever it is except for the start of the string.

Expression that i'am using -> ^[\p{L}\d\s\-](.*[а-яА-Я].*)+$

  1. ok -> loremфффф ф
  2. ok -> ipsuфmл
  3. ok -> ffffл
  4. ok -> фgfфdфg
  5. ок -> ллlorem
  6. fail -> лlorem (because the first letter is in cyrillic and it is the only one)

https://regex101.com/


Solution

  • You can use

    ^\P{Cyrillic}*\p{Cyrillic}.*
    

    See the regex demo.

    If you want to only deal with Russian chars, you can replace \p{Cyrillic} with [а-яёА-ЯЁ] and \P{Cyrillic} with [^а-яёА-ЯЁ].

    Details:

    To match multiline strings, add (?s) at the start, or replace . with a [\w\W] workaround construct.