Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

r"
"
gm

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"Column ([0-9]+): (.*)" test_str = ("File name: Pandora101s1_Izana_L2Tot_rnvs1p1-7.txt\n" "File generation date: 20200602T091315Z\n" "Data description: Level 2 total columns file\n" "Data file version: rnvs1p1-7\n" "Data product status: Nitrogen dioxide data are official\n" "Local principal investigator: Alberto Redondas\n" "Network principal investigator: Alexander Cede\n" "Instrument type: Pandora\n" "Instrument number: 101\n" "Spectrometer number: 1\n" "Processing software version used: BlickP v1.7.16\n" "Full location name: Izana Atmospheric Research Center\n" "Short location name: Izana\n" "Country of location: Spain\n" "Location latitude [deg]: 28.3090\n" "Location longitude [deg]: -16.4994\n" "Location altitude [m]: 2360\n" "Data start time: 20181126T101552Z\n" "Data end time: 20200601T195357Z\n" "Data caveats: None\n" "---------------------------------------------------------------------------------------\n" "Column 1: UT date and time for center of measurement, yyyymmddThhmmssZ (ISO 8601)\n" "Column 2: Fractional days since 1-Jan-2000 UT midnight for center of measurement\n" "Column 3: Effective duration of measurement in seconds\n" "Column 4: Solar zenith angle for center of measurement in degree\n" "Column 5: Solar azimuth for center of measurement in degree, 0=north, increases clockwise\n" "Column 6: Lunar zenith angle for center of measurement in degree\n" "Column 7: Lunar azimuth for center of measurement in degree, 0=north, increases clockwise\n" "Column 8: Nitrogen dioxide total vertical column amount [Dobson Units], -9e99=retrieval not successful\n" "Column 9: Uncertainty of nitrogen dioxide total vertical column amount [Dobson Units] based on measured uncertainty, -8=retrieval not successful, -1=cross section is zero in this wavelength range, -3=spectral fitting was done, but no uncertainty could be retrieved\n" "Column 10: Direct nitrogen dioxide air mass factor\n" "Column 11: Diffuse correction applied before fitting at effective fitting wavelength for nitrogen dioxide [%], 0=no diffuse correction applied or fitting not successful, >0=measured diffuse correction, <0=(negative value of) calculated diffuse correction\n" "Column 12: L2 data quality flag for nitrogen dioxide: 0=assured high quality, 1=assured medium quality, 2=assured low quality, 10=not-assured high quality, 11=not-assured medium quality, 12=not-assured low quality, 20=unusable high quality, 21=unusable medium quality, 22=unusable low quality\n" "Column 13: Sum over 2^i using those i, for which the corresponding L2 data quality parameter for nitrogen dioxide exceeds the DQ1 limit, 0=L2Fit data quality above 0, 1=Uncertainty too high, 2=Signal to noise ratio too low, 3=Air mass factor too large\n" "Column 14: Sum over 2^i using those i, for which the corresponding L2 data quality parameter for nitrogen dioxide exceeds the DQ2 limit (same parameters as for DQ1)\n" "Column 15: Fitting result index: 0,1,2=no error or warning, 3,4=warning, >4=error\n" "Column 16: Normalized rms of spectral fitting residuals weighted with measured uncertainty, -9=fitting not successful or no uncertainty given\n" "Column 17: Expected normalized rms of weighted spectral fitting residuals based on measured uncertainty, -9=fitting not successful or no uncertainty given\n" "Column 18: Expected normalized rms of weighted spectral fitting residuals based on instrumental uncertainty, -9=fitting not successful or no uncertainty given\n" "Column 19: Mean value of measured data inside fitting window [same units as measurements]\n" "Column 20: Climatological station pressure [mbar]\n" "Column 21: Data processing type index\n" "Column 22: Calibration file version\n" "Column 23: Calibration file validity starting date\n" "Column 24: Level 2 Fit data quality flag: 0=assured high quality, 1=assured medium quality, 2=assured low quality, 10=not-assured high quality, 11=not-assured medium quality, 12=not-assured low quality\n" "Column 25: Sum over 2^i using those i, for which the corresponding L2Fit data quality parameter exceeds the DQ1 limit, 0=L1 data quality above 0, 1=Spectral fitting was not successful, 2=Weighted rms of spectral fitting too large, 3=Wavelength shift too large\n" "Column 26: Sum over 2^i using those i, for which the corresponding L2Fit data quality parameter exceeds the DQ2 limit (same parameters as for DQ1)\n" "Column 27: Level 1 data quality flag: 0=assured high quality, 1=assured medium quality, 2=assured low quality, 10=not-assured high quality, 11=not-assured medium quality, 12=not-assured low quality\n" "Column 28: Sum over 2^i using those i, for which the corresponding L1 data quality parameter exceeds the DQ1 limit, 0=Saturated data, 1=Too few dark counts measurements, 2=No temperature given or effective temperature too different from the reference temperature, 3=Dark count too high, 4=Unsuccessful dark background fitting, 5=Absolute value of estimated average residual stray light level too high, 6=Although attempted, no wavelength change could be retrieved, 7=Absolute value of retrieved wavelength shift too large, 8=Retrieved wavelength shift differs too much from the shift predicted by the effective temperature\n" "Column 29: Sum over 2^i using those i, for which the corresponding L1 data quality parameter exceeds the DQ2 limit (same parameters as for DQ1)\n" "Column 30: Wavelength effective temperature [�C], 999=no effective temperature given\n" "Column 31: Estimated average residual stray light level [%] (only valid for stray light correction methods 2 and higher)\n" "Column 32: Retrieved wavelength shift from level 1 data [nm], -9=no wavelength change determination\n" "Column 33: Retrieved wavelength shift from spectral fitting [nm], -9=no wavelength change fitting\n" "Column 34: Integration time [ms]\n" "Column 35: Number of dark count cycles\n" "Column 36: Effective position of filterwheel #1, 0=filterwheel not used, 1-9 are valid positions\n" "Column 37: Effective position of filterwheel #2, 0=filterwheel not used, 1-9 are valid positions\n" "---------------------------------------------------------------------------------------\n" "20181126T101552Z 6904.42769 32.14 62.23 137.99 85.08 291.15 8.5187e-02 2.5145e-03 2.138 0.00e+00 0 0 0 0 2.359e-04 1.827e-04 7.550e-05 4.1258e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.61 -0.00156 -0.00357 17.6 430 2 4\n" "20181126T101636Z 6904.42820 32.17 62.12 138.14 85.23 291.22 8.6831e-02 1.3378e-03 2.130 0.00e+00 0 0 0 0 2.266e-04 9.714e-05 7.602e-05 4.0671e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00154 -0.00344 17.3 437 2 4\n" "20181126T101720Z 6904.42871 32.24 62.01 138.29 85.37 291.30 8.0801e-02 3.0729e-03 2.123 0.00e+00 0 0 0 0 1.934e-04 2.214e-04 7.960e-05 3.7157e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00134 -0.00337 18.7 406 2 4\n" "20181126T101804Z 6904.42921 32.25 61.90 138.45 85.52 291.38 7.5402e-02 3.7567e-03 2.116 0.00e+00 0 0 0 0 1.924e-04 2.699e-04 7.954e-05 3.7050e+09 775 2 3 20181126 10 0 0 10 0 0 21.98 0.61 -0.00131 -0.00332 19.3 393 2 4\n" "20181126T101848Z 6904.42972 32.12 61.80 138.60 85.66 291.46 7.3074e-02 4.6694e-03 2.108 0.00e+00 0 0 0 0 1.949e-04 3.340e-04 7.938e-05 3.7260e+09 775 2 3 20181126 10 0 0 10 0 0 21.98 0.61 -0.00126 -0.00333 20.2 376 2 4\n" "20181126T102220Z 6904.43218 32.21 61.29 139.33 86.36 291.83 7.7763e-02 2.6556e-03 2.074 0.00e+00 0 0 0 0 2.149e-04 1.872e-04 7.559e-05 4.1162e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.61 -0.00133 -0.00343 17.1 443 2 4\n" "20181126T102305Z 6904.43270 32.28 61.18 139.49 86.50 291.92 6.1693e-02 2.0919e-03 2.067 0.00e+00 0 0 0 0 2.067e-04 1.472e-04 7.778e-05 3.8893e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00147 -0.00337 18.0 422 2 4\n" "20181126T102349Z 6904.43321 32.65 61.07 139.65 86.65 291.99 6.9311e-02 2.7602e-03 2.060 0.00e+00 0 0 0 0 1.932e-04 1.933e-04 7.793e-05 3.8661e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00130 -0.00319 18.7 406 2 4\n" "20181126T102434Z 6904.43373 32.63 60.97 139.81 86.80 292.07 8.6315e-02 1.8517e-03 2.054 0.00e+00 0 0 0 0 2.313e-04 1.296e-04 7.701e-05 3.9533e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00141 -0.00321 18.0 420 2 4\n" "20181126T102518Z 6904.43424 33.25 60.86 139.96 86.94 292.15 8.3879e-02 1.7818e-03 2.047 0.00e+00 0 0 0 0 2.218e-04 1.241e-04 7.609e-05 4.0593e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00151 -0.00318 17.9 422 2 4\n" "20181126T102855Z 6904.43675 32.17 60.36 140.74 87.65 292.54 6.8953e-02 1.7801e-03 2.015 0.00e+00 0 0 0 0 2.005e-04 1.220e-04 8.525e-05 3.2319e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.61 -0.00146 -0.00320 21.1 360 2 4\n" "20181126T102939Z 6904.43726 32.15 60.25 140.89 87.79 292.62 7.4838e-02 3.3267e-03 2.009 0.00e+00 0 0 0 0 2.090e-04 2.273e-04 8.618e-05 3.1564e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.61 -0.00144 -0.00309 22.5 337 2 4\n" "20181126T103023Z 6904.43777 32.28 60.15 141.05 87.93 292.70 7.7249e-02 3.3359e-03 2.003 0.00e+00 0 0 0 0 2.002e-04 2.267e-04 8.018e-05 3.6459e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.61 -0.00143 -0.00309 20.5 371 2 4\n" "20181126T103107Z 6904.43828 32.20 60.05 141.21 88.08 292.78 8.1582e-02 2.7337e-03 1.997 0.00e+00 0 0 0 0 1.909e-04 1.857e-04 7.777e-05 3.8824e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00141 -0.00301 18.3 415 2 4\n" "20181126T103151Z 6904.43879 32.14 59.95 141.37 88.22 292.86 5.9658e-02 1.9235e-03 1.991 0.00e+00 0 0 0 0 1.922e-04 1.301e-04 7.570e-05 4.1000e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.61 -0.00144 -0.00310 18.3 414 2 4\n" "20181126T103521Z 6904.44122 32.22 59.47 142.14 88.90 293.25 8.6088e-02 1.9366e-03 1.963 0.00e+00 0 0 0 0 2.235e-04 1.296e-04 7.388e-05 4.3015e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.61 -0.00134 -0.00316 16.7 454 2 4\n" "20181126T103605Z 6904.44173 32.12 59.38 142.30 89.04 293.33 8.6975e-02 1.8767e-03 1.957 0.00e+00 0 0 0 0 2.032e-04 1.248e-04 7.309e-05 4.4038e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00139 -0.00304 16.5 460 2 4\n" "20181126T103649Z 6904.44224 32.34 59.28 142.47 89.18 293.41 7.1906e-02 1.4919e-03 1.952 0.00e+00 0 0 0 0 1.972e-04 9.903e-05 7.230e-05 4.4976e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00137 -0.00297 16.0 472 2 4\n" "20181126T103733Z 6904.44274 32.24 59.18 142.63 89.33 293.49 7.7980e-02 1.8454e-03 1.946 0.00e+00 0 0 0 0 1.848e-04 1.220e-04 7.314e-05 4.3920e+09 775 2 3 20181126 10 0 0 10 0 0 21.88 0.62 -0.00123 -0.00294 16.5 460 2 4\n" "20181126T103817Z 6904.44325 32.23 59.08 142.79 89.47 293.") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.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