Regular Expressions 101

Save & Share

  • Regex Version: ver. 14
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
No Match

@"
"

Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"(\d+\s+Timer.*?PHY Status 0x[01]+ - 0x[01].*?tx_p3a_d1en[\s]+0[x\w])+\s+" test_str = ("000 Timer 0x00000000_0002a465 - 0x00000000_0021453e us: Gen1 - Gen1, DETECT.QUIET - DETECT.QUIET: Status 0x00000030 - 0x00000030: L2R_reason 0x00000000: PHY Status 0x01010000 - 0x01010000\n\n" " Lane 00:\n\n" " pga_gain 3, pga_off1 0, pga_off2 1, ph_ofs_t -44,\n\n" " cdfe_a2 52, cdfe_a3 64, cdfe_a4 118, cdfe_a5 71, cdfe_a6 12, cdfe_a7 124, cdfe_a8 24, cdfe_a9 76, cdfe_a10 49,\n\n" " zobel_a_gain 12, zobel_b_gain 0, zobel_dc_ofs 260, dc_ofs 25, udfe_thr_0 -152, udfe_thr_1 14, median_amp 179,\n\n" " cdru_lock_count 0, eh_workaround_stat 0x0, los_toggle_cnt 0x8000, adapt_time 207872, cdr_lock_toggle_cnt 0x3000, jat_stat 0x804d\n\n" " fs_obs 0, lf_obs 0, pre_cursor 0, cursor 0, post_cursor 0, usp_tx_preset 0x0, dsp_tx_preset 0x0\n\n" " tx_p1a_d1en 0x30, tx_p1a_d2en 0xf, tx_p1a_amp_red 0x0, tx_p1b_d1en 0x3f, tx_p1b_d2en 0x0, tx_p1b_amp_red 0x0\n\n" " tx_p2a_d1en 0x3f, tx_p2a_d2en 0x0, tx_p2a_amp_red 0x0, tx_p2b_d1en 0x3f, tx_p2b_d2en 0x0, tx_p2b_amp_red 0x0 tx_p3a_d1en 0x28\n\n" " Lane 01:\n\n" " pga_gain 15, pga_off1 24, pga_off2 6, ph_ofs_t -57,\n\n" " cdfe_a2 -106, cdfe_a3 120, cdfe_a4 -80, cdfe_a5 -31, cdfe_a6 -13, cdfe_a7 127, cdfe_a8 96, cdfe_a9 127, cdfe_a10 4,\n\n" " zobel_a_gain 0, zobel_b_gain 0, zobel_dc_ofs 457, dc_ofs 217, udfe_thr_0 -215, udfe_thr_1 219, median_amp 176,\n\n" " cdru_lock_count 0, eh_workaround_stat 0x0, los_toggle_cnt 0x8000, adapt_time 207872, cdr_lock_toggle_cnt 0x3000, jat_stat 0x804d\n\n" " fs_obs 0, lf_obs 0, pre_cursor 0, cursor 0, post_cursor 0, usp_tx_preset 0x0, dsp_tx_preset 0x0\n\n" " tx_p1a_d1en 0x30, tx_p1a_d2en 0xf, tx_p1a_amp_red 0x0, tx_p1b_d1en 0x3f, tx_p1b_d2en 0x0, tx_p1b_amp_red 0x0\n\n" " tx_p2a_d1en 0x3f, tx_p2a_d2en 0x0, tx_p2a_amp_red 0x0, tx_p2b_d1en 0x3f, tx_p2b_d2en 0x0, tx_p2b_amp_red 0x0 tx_p3a_d1en 0x28\n\n") matches = re.search(regex, test_str) if matches: print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group())) for groupNum in range(0, len(matches.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html