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
No Match

/
/
igm

Test String

Code Generator

Generated Code

const regex = /([\d\.]+%) identity/igm; // Alternative syntax using RegExp constructor // const regex = new RegExp('([\\d\\.]+%) identity', 'igm') const str = `# /data/spine/bin/external/fasta/bin/glsearch36 -b 2 -m 9i -q /tmp/temp.seq /data/spine/databases/UniProt/sprot.compact_headers.distinct.mouse GLSEARCH performs a global-query/local-library search version 36.3.6 Nov, 2013(preload9) Query: /tmp/temp.seq 1>>>seq - 299 aa Library: /data/spine/databases/UniProt/sprot.compact_headers.distinct.mouse 9277236 residues in 16315 sequences Statistics: Unscaled normal statistics: mu= -50.7059 var=2892.0306 Ztrim: 0 statistics sampled from 13365 (13367) to 13365 sequences Algorithm: Global/Local affine Needleman-Wunsch (2007) (6.0 April 2007) Parameters: BL50 matrix (15:-5), open/ext: -12/-2 Scan time: 11.560 The best scores are: n-w bits E(16315) %_id %_sim alen SP|P61375|LHX5_MOUSE ( 402) 1361 66.3 5.7e-148 0.685 0.868 302 SP|P50481|LHX3_MOUSE ( 400) 331 30.8 1e-08 0.319 0.524 307 >>>seq, 299 aa vs /data/spine/databases/UniProt/sprot.compact_headers.distinct.mouse library >>SP|P61375|LHX5_MOUSE (402 aa) n-w opt: 1361 Z-score: 312.5 bits: 66.3 E(16315): 5.7e-148 global/local score: 1361; 68.5% identity (86.8% similar) in 302 aa overlap (1-299:107-400) 10 20 30 seq YIDENKFVCKEDYLSNSSVAKENSLHSATT :::::::::.::::.::. ::.::.:... SP|P61 VRKARSKVFHLNCFTCMVCNKQLSTGEELYVIDENKFVCKDDYLSSSSL-KEGSLNSVSS 80 90 100 110 120 130 40 50 60 70 80 90 seq GSDPSLSPDSQDPSQDDAKDSESANVSDKEGGSNENDDQNLGAKRRGPRTTIKAKQLETL .: ::::: ::: ::: :...... :::: ..:::..:: :.::::::::::::::::: SP|P61 CTDRSLSPDLQDPLQDDPKETDNSTSSDKETANNENEEQNSGTKRRGPRTTIKAKQLETL 140 150 160 170 180 190 100 110 120 130 140 150 seq KAAFAATPKPTRHIREQLAQETGLNMRVIQVWFQNRRSKERRMKQLSALGARRHAFFRSP :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SP|P61 KAAFAATPKPTRHIREQLAQETGLNMRVIQVWFQNRRSKERRMKQLSALGARRHAFFRSP 200 210 220 230 240 250 160 170 180 190 200 210 seq RRMRPLVDRLEPGELIPNGPFSFYGDYQSEYYGPGGNYDFFPQGPPSSQAQTPVDLPFVP :::::: ::. .:.. . :...::::::.::.:::::::: .:::: :::.:.: :. SP|P61 RRMRPLGGRLDESEMLGSTPYTYYGDYQSDYYAPGGNYDFFAHGPPS-QAQSPADSSFLA 260 270 280 290 300 310 220 230 240 250 260 seq SSGPSGTPLGGLDHPLPGHHPSSEAQRFTDILAHPPGDSPSPEPSLPGPLHSMSAEVF-- .:::..::::.:. :: : : ... ::::...:: :.:::::.::: :: : .::: SP|P61 ASGPGSTPLGALEPPLAGPH-GADNPRFTDMISHP--DTPSPEPGLPGALHPMPGEVFSG 320 330 340 350 360 370 270 280 290 seq GPSPPFSSLSVNGGASYGNHLSHP-PEMNEAA :::::: ..: ..:.. :::: ::.:::: SP|P61 GPSPPFP---MSGTSGYSGPLSHPNPELNEAAVW 380 390 400 >>SP|P50481|LHX3_MOUSE (400 aa) n-w opt: 331 Z-score: 121.0 bits: 30.8 E(16315): 1e-08 global/local score: 331; 31.9% identity (52.4% similar) in 307 aa overlap (1-299:99-365) 10 20 seq YIDENKFVCK-EDYLSN-SSVAKENSLHSA : .. : . .:.. . : .. SP|P50 AERCFSRGESVYCKDDFFKRFGTKCAACQLGIPPTQVVRRAQDFVYHLHCFACVVCKRQL 70 80 90 100 110 120 30 40 50 60 70 80 seq TTGSDPSLSPDSQDPSQDDAKDSESANVSDKEGGSNENDDQNLGAKRRGPRTTIKAKQLE .::.. : ::. . : :.:. . :. ::: ::::: ::::: SP|P50 ATGDEFYLMEDSRLVCK---ADYETAKQREAEAT----------AKR--PRTTITAKQLE 130 140 150 160 170 90 100 110 120 130 140 seq TLKAAFAATPKPTRHIREQLAQETGLNMRVIQVWFQNRRSKERRMKQLSALGARRHAFFR :::.:. ..:::.::.::::..::::.:::.::::::::.::.:.:. .: : .:: SP|P50 TLKSAYNTSPKPARHVREQLSSETGLDMRVVQVWFQNRRAKEKRLKK-DAGRQRWGQYFR 180 190 200 210 220 230 150 160 170 180 190 200 seq SPRRMRPLVDRLEPGELIPNGPFSFYGDYQSEYYGPGGNYDFFPQGPPSSQAQTPVDLPF . .: : : .: .: : .. . :: . :.. . SP|P50 NMKRSRG----------------SSKSDKDSIQEGQDSDAEVSFTDEPSMADMGPANGLY 240 250 260 270 210 220 230 240 250 260 seq VPSSGPS---GTPLGGLDHPLPGHHPSSEAQRFTDILAHPP-GDSPSPEP--SLPGPLHS . :. : :.::: : . ... .. : : ::: ::::: SP|P50 SSLGEPAPALGRPVGGLGSFTLDHGGLTGPEQYRELRPGSPYGIPPSPAAPQSLPGPQPL 280 290 300 310 320 330 270 280 290 seq MSAEVFGPSPPFSSLSVNGGASYGNHLSHPPEMNEAA .:. :. : ..::. .. :. :: : : SP|P50 LSSLVY----PDTNLSLVPSGPPGG----PPPMRVLAGNGPSSDLSTESSSGYPDFPASP 340 350 360 370 380 SP|P50 ASWLDEVDHAQF 390 400 >>>/// 299 residues in 1 query sequences 9277236 residues in 16315 library sequences Tcomplib [36.3.6 Nov, 2013(preload9)] (8 proc in memory [0G]) start: Thu Sep 3 20:44:48 2015 done: Thu Sep 3 20:44:55 2015 Total Scan time: 11.560 Total Display time: 0.010 Function used was GLSEARCH [36.3.6 Nov, 2013(preload9)]`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions