Regular Expressions 101

Save & Share

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^[a-zA-Z\u0600-\u06FF,-\s\d][\s\d\a-zA-Z\u0600-\u06FF,-]*$
/
i
^ asserts position at start of the string
Match a single character present in the list below
[a-zA-Z\u0600-\u06FF,-\s\d]
a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case insensitive)
\u0600-\u06FF matches a single character in the range between ؀ (index 1536) and ۿ (index 1791) (case insensitive)
, matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
- matches the character - with index 4510 (2D16 or 558) 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!
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\d matches a digit (equivalent to [0-9])
Match a single character present in the list below
[\s\d\a-zA-Z\u0600-\u06FF,-]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\d matches a digit (equivalent to [0-9])
\a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case insensitive)
\u0600-\u06FF matches a single character in the range between ؀ (index 1536) and ۿ (index 1791) (case insensitive)
, matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
- matches the character - with index 4510 (2D16 or 558) 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!
$ asserts position at the end of the string
Global pattern flags
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

/
/
i

Test String