Please wait...

小波Note

四川 · 成都市8 ℃
English
/
/

Match success
  • 1
  • 0
  • 2
  • 4

Regular expressions (regex or regexp for short) are patterns used to match character combinations in strings. Regular expressions can be used for searching, editing, or processing text. They are widely used in many programming languages and tools.

README.md
        Match Chinese characters: [\u4E00-\u9FA5]
Match double-byte characters (including Chinese characters): [^\x00-\xFF]
Chinese ID number, last digit or X: d{17}[d|X|x]
Chinese mobile phone number: 1[3-9]d{9}
Chinese landline number: d{3}-d{8}|d{4}-d{7}
Chinese postal code: [1-9]d{5}(?!d)
Email validation: w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
Match URL: [a-zA-z]+://[^s]*
Match IPv4 address: d+.d+.d+.d+

    

Basic Syntax

Literal characters: Match themselves. For example, the regular expression abc matches the string "abc".

Metacharacters: Characters with special meanings. For example:

  1. .: Matches any single character except newline.
  2. ^: Matches the beginning of the string.
  3. $: Matches the end of the string.
  4. *: Matches the preceding subexpression zero or more times.
  5. +: Matches the preceding subexpression one or more times.
  6. ?: Matches the preceding subexpression zero or one time.
  7. |: Indicates an OR operation, for example, a|b matches "a" or "b".
  8. (): Used for grouping and capturing.
  9. []: Matches any one of the characters inside the brackets, for example, abc matches "a", "b", or "c".
  10. {}: Matches the preceding subexpression a specified number of times, for example, a{2} matches "aa".
  11. Escape character: Use a backslash to escape metacharacters, making them lose their special meaning. For example, . matches a period.
  12. g: Global match.
  13. i: Ignore case.
  14. m: Multiline match.
  15. s: Single-line match.
  16. u: Unicode match.

Some Uses

  1. Match digits: d
  2. Match non-digits: D
  3. Match whitespace characters: s
  4. Match non-whitespace characters: S
  5. Match word characters: w
  6. Match non-word characters: W
  7. Match newline:
  8. Match tab:
  9. Match carriage return:
  10. Match any character: sS
  11. Match any character: wW
  12. Match any character: dD
  13. Match any character: ^
  14. Match Chinese characters: 一-龥
  15. -: Indicates a range, for example, 0-9 matches digits from 0 to 9.
  16. ?: Non-greedy match, for example, a+? matches "a" or "aa".
  17. (?=exp): Positive lookahead, matches the position before exp.
  18. (?!exp): Negative lookahead, matches the position not followed by exp.
  19. (?<=exp): Positive lookbehind, matches the position after exp.
  20. (?<!exp): Negative lookbehind, matches the position not preceded by exp.
  21. : Matches a word boundary.
  22. B: Matches a non-word boundary.
  23. x|y: Matches x or y.
Astral