Regular Expressions 101

Save & Share

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

/
/
gm

Test String

Substitution

Processing...

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"([\w_]+)\t([\w_]+)\t([\w_]+)" test_str = ("albatross_v7 g_coeffExit ExtBandsExitCoeff\n" "albatross_v7 g_dayFilter ExtDayNotToTrade\n" "albatross_v7 g_period ExtBandsPeriod\n" "albatross_v7 g_tradeDuration ExtTimeWindowDuration\n" "albatross_v7 g_tradeStartTime ExtTimeWindowStart\n" "double_rsi g_coeffRSIFast ExtCoeffRsiFast\n" "double_rsi g_dayFilter ExtDayNotToTrade\n" "double_rsi g_RSIDiffLevel ExtMinRsiDiff\n" "double_rsi g_RSIPeriod ExtSlowRsiPeriod\n" "double_rsi g_tradeDuration ExtTimeWindowDuration\n" "double_rsi g_tradeStartTime ExtTimeWindowStart\n" "double_rsi g_trend ExtTrendModeFilter\n" "double_rsi g_volatility ExtVolatilityModeFilter\n" "double_rsi_h4_ei g_coeffRSIFast ExtCoeffRsiFast\n" "double_rsi_h4_ei g_dayFilter ExtDayNotToTrade\n" "double_rsi_h4_ei g_exitParameter ExtExitParameter\n" "double_rsi_h4_ei g_exitType ExtExitType\n" "double_rsi_h4_ei g_RSIDiffLevel ExtMinRsiDiff\n" "double_rsi_h4_ei g_RSIPeriod ExtSlowRsiPeriod\n" "double_rsi_h4_ei g_tradeDuration ExtTimeWindowDuration\n" "double_rsi_h4_ei g_tradeStartTime ExtTimeWindowStart\n" "double_rsi_h4_ei g_trend ExtTrendModeFilter\n" "double_rsi_h4_ei g_volatility ExtVolatilityModeFilter\n" "hook g_CoeffExit ExtExitCoeff\n" "hook g_Cycle ExtCycleModeFilter\n" "hook g_CycleLevel ExtCycleLevel\n" "hook g_CyclePeriod ExtCyclePeriod\n" "hook g_Exit ExtExitType\n" "hook g_Order ExtOrderMode\n" "hook g_OrderBar ExtBarsNumber\n" "hook g_OrderPendingBar ExtOrderDeleteBar\n" "hook g_RSIPeriod ExtRsiPeriod\n" "hook g_Setup ExtEntrySetup\n" "hook g_Threshold ExtRsiThreshold\n" "hook g_Trend ExtTrendModeFilter\n" "hook g_TrendPeriod ExtTrendPeriod\n" "hook g_Volatility ExtVolatilityModeFilter\n" "hook g_TradeDuration ExtTimeWindowDuration\n" "hook g_TradeStartTime ExtTimeWindowStart\n" "metaphor_v5 g_barsNumber ExtBarsNumber\n" "metaphor_v5 g_coeffBarsExit ExtExitCoeffBars\n" "metaphor_v5 g_dayFilter ExtDayNotToTrade\n" "metaphor_v5 g_tradeDuration ExtTimeWindowDuration\n" "metaphor_v5 g_tradeStartTime ExtTimeWindowStart\n" "metaphor_v6 g_barsNumber ExtBarsNumber\n" "metaphor_v6 g_BBKCPeriod ExtBbkcPeriod\n" "metaphor_v6 g_coeffBarsExit ExtExitCoeffBars\n" "metaphor_v6 g_dayFilter ExtDayNotToTrade\n" "metaphor_v6 g_tradeDuration ExtTimeWindowDuration\n" "metaphor_v6 g_tradeStartTime ExtTimeWindowStart\n" "metaphor_v6_quick g_barsNumber ExtBarsNumber\n" "metaphor_v6_quick g_BBKCPeriod ExtBbkcPeriod\n" "metaphor_v6_quick g_coeffBarsExit ExtExitCoeffBars\n" "metaphor_v6_quick g_dayFilter ExtDayNotToTrade\n" "metaphor_v6_quick g_tradeDuration ExtTimeWindowDuration\n" "metaphor_v6_quick g_tradeStartTime ExtTimeWindowStart\n" "rsi_snr g_dayFilter ExtDayNotToTrade\n" "rsi_snr g_RSIPeriod ExtRsiPeriod\n" "rsi_snr g_SNRLevel ExtSnrLevel\n" "rsi_snr g_SNRPeriod ExtSnrPeriod\n" "rsi_snr g_tradeDuration ExtTimeWindowDuration\n" "rsi_snr g_tradeStartTime ExtTimeWindowStart\n" "rsi_snr g_trend ExtTrendModeFilter\n" "rsi_snr g_volatility ExtVolatilityModeFilter\n" "rsi_snr_h1_ei g_dayFilter ExtDayNotToTrade\n" "rsi_snr_h1_ei g_exitParameter ExtExitParameter\n" "rsi_snr_h1_ei g_exitType ExtExitType\n" "rsi_snr_h1_ei g_RSIPeriod ExtRsiPeriod\n" "rsi_snr_h1_ei g_SNRLevel ExtSnrLevel\n" "rsi_snr_h1_ei g_SNRPeriod ExtSnrPeriod\n" "rsi_snr_h1_ei g_tradeDuration ExtTimeWindowDuration\n" "rsi_snr_h1_ei g_tradeStartTime ExtTimeWindowStart\n" "rsi_snr_h1_ei g_trend ExtTrendModeFilter\n" "rsi_snr_h1_ei g_volatility ExtVolatilityModeFilter\n" "rush_v2_h1 g_counter ExtEntrySignalCounter\n" "rush_v2_h1 g_dayFilter ExtDayNotToTrade\n" "rush_v2_h1 g_exitBar ExtExitBar\n" "rush_v2_h1 g_tradeDuration ExtTimeWindowDuration\n" "rush_v2_h1 g_tradeStartTime ExtTimeWindowStart\n" "super_smoother_ei g_dayFilter ExtDayNotToTrade\n" "super_smoother_ei g_DiffPeriod ExtRsiPeriodDiff\n" "super_smoother_ei g_exitParameter ExtExitParameter\n" "super_smoother_ei g_exitType ExtExitType\n" "super_smoother_ei g_PeriodFast ExtFastRsiPeriod\n" "super_smoother_ei g_tradeDuration ExtTimeWindowDuration\n" "super_smoother_ei g_tradeStartTime ExtTimeWindowStart\n" "super_smoother_ei g_trend ExtTrendModeFilter\n" "super_smoother_ei g_volatility ExtVolatilityModeFilter") subst = "update t_strategy\\n set t_strategy_parameters = replace(t_strategy_parameters, '$2', '$3')\\n where t_strategy_ea = '$1' and\\n t_strategy_parameters like '%$2%' and\\n t_strategy_version = '1.1';" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 0, re.MULTILINE) if result: print (result) # 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