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\-](.*[а-яА-Я].*) $
- ok -> loremфффф ф
- ok -> ipsuфmл
- ok -> ffffл
- ok -> фgfфdфg
- ок -> ллlorem
- fail -> лlorem (because the first letter is in cyrillic and it is the only one)
CodePudding user response:
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:
^- start of string\P{Cyrillic}*- zero or more chars other than Cyrillic\p{Cyrillic}- a Cyrillic char.*- zero or more chars other than line break chars as many as possible.
To match multiline strings, add (?s) at the start, or replace . with a [\w\W] workaround construct.
