Regular Expressions 101

@regex101
Donate
Sponsor
Contact
Bug Reports & Feedback
Wiki
Whats new?

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python 2.7
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^([A-Z]([ -][A-Z])?|[А-ЯЁ]([ -][А-ЯЁ])?)$
/
gmi
^ asserts position at start of a line
1st Capturing Group
([A-Z]([ -][A-Z])?|[А-ЯЁ]([ -][А-ЯЁ])?)
1st Alternative
[A-Z]([ -][A-Z])?
Match a single character present in the list below
[A-Z]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case insensitive)
2nd Capturing Group
([ -][A-Z])?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[ -]
matches the character literally (case insensitive)
- matches the character - literally (case insensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
Match a single character present in the list below
[A-Z]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case insensitive)
2nd Alternative
[А-ЯЁ]([ -][А-ЯЁ])?
Match a single character present in the list below
[А-ЯЁ]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
А-Я matches a single character in the range between А (index 1040) and Я (index 1071) (case insensitive)
Ё matches the character Ё literally (case insensitive)
3rd Capturing Group
([ -][А-ЯЁ])?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[ -]
matches the character literally (case insensitive)
- matches the character - literally (case insensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
Match a single character present in the list below
[А-ЯЁ]
$ asserts position at the end of a line
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
gmi

Test String