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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

@"
"
gmi

Test String

Code Generator

Generated Code

use strict; my $str = ' BRIEF CONTENTS Chapter1 Basic Concepts 1 Chapter2 Resistive Circuits 24 Chapter3 Nodal and Loop Analysis Techniques 89 Chapter4 Operational Amplifiers 147 Chapter5 Additional Analysis Techniques 171 Chapter6 Capacitance and Inductance 219 Chapter7 First- and Second-Order Transient Circuits 252 Chapter8 AC Steady-State Analysis 305 Chapter9 Steady-State Power Analysis 362 Chapter10 Magnetically Coupled Networks 411 Chapter11 Polyphase Circuits 450 Chapter12 Variable-Frequency Network Performance 482 Chapter13 The Laplace Transform 543 Chapter14 Application of the Laplace Transform to Circuit Analysis 569 Chapter15 Fourier Analysis Techniques 617 Appendix Complex Numbers 659 vi FM.indd viFM.indd vi 21/11/14 11:11 AM21/11/14 11:11 AM CONTENTS Preface ix 5.3 Thévenin’s and Norton’s Theorems  179 Chapterone 5.4 Maximum Power Transfer  197 Summary  202 Basic Concepts 1 Problems  202 1.1 System of Units 2 Chaptersix 1.2 Basic Quantities 2 Capacitance and Inductance 219 1.3 Circuit Elements  8 Summary  17 6.1 Capacitors  220 Problems  18 6.2 Inductors  227 6.3 Capacitor and Inductor Combinations  236 Chaptertwo Summary  241 Resistive Circuits 24 Problems  241 2.1 Ohm’s Law  25 Chapterseven 2.2 Kirchhoff’s Laws  30 First- and Second-Order Transient Circuits 252 2.3 Single-Loop Circuits  38 2.4 Single-Node-Pair Circuits  45 7.1 Introduction  253 2.5 Series and Parallel Resistor Combinations  50 7.2 First-Order Circuits  254 2.6 Wye Delta Transformations  59 7.3 Second-Order Circuits  275 2.7 Circuits with Dependent Sources  63 Summary  289 Summary  68 Problems  289 Problems  69 Chaptereight Chapterthree AC Steady-State Analysis 305 Nodal and Loop Analysis Techniques 89 8.1 Sinusoids  306 3.1 Nodal Analysis  90 8.2 Sinusoidal and Complex Forcing Functions  309 3.2 Loop Analysis  111 8.3 Phasors  312 Summary  128 8.4 Phasor Relationships for Circuit Elements  314 Problems  129 8.5 Impedance and Admittance  318 8.6 Phasor Diagrams  325 Chapterfour 8.7 Basic Analysis Using Kirchhoff’s Laws  328 Operational Amplifiers 147 8.8 Analysis Techniques  331 Summary  344 4.1 Introduction  148 Problems  344 4.2 Op-Amp Models  148 4.3 Fundamental Op-Amp Circuits  154 Chapternine Summary  163 Steady-State Power Analysis 362 Problems  163 9.1 Instantaneous Power  363 Chapterfi ve 9.2 Average Power  364 Additional Analysis Techniques 171 9.3 Maximum Average Power Transfer  369 9.4 Effective or rms Values  374 5.1 Introduction  172 9.5 The Power Factor  377 5.2 Superposition  174 9.6 Complex Power  379 vii FM.indd viiFM.indd vii 21/11/14 11:11 AM21/11/14 11:11 AM viii CONTENTS 9.7 Power Factor Correction  384 13.3 Transform Pairs  547 9.8 Single-Phase Three-Wire Circuits  388 13.4 Properties of the Transform  549 9.9 Safety Considerations  391 13.5 Performing the Inverse Transform  551 Summary  399 13.6 Convolution Integral  557 Problems  399 13.7 Initial-Value and Final-Value Theorems  560 13.8 Solving Differential Equations with Laplace Chapterten Transforms  562 Magnetically Coupled Networks 411 Summary  564 10.1 Mutual Inductance  412 Problems  564 10.2 Energy Analysis  423 Chapterfourteen 10.3 The Ideal Transformer  426 Application of the Laplace Transform to 10.4 Safety Considerations   436 Circuit Analysis 569 Summary  437 Problems  438 14.1 Laplace Circuit Solutions  570 14.2 Circuit Element Models  571 Chaptereleven 14.3 Analysis Techniques  573 Polyphase Circuits 450 14.4 Transfer Function  586 11.1 Three-Phase Circuits  451 14.5 Steady-State Response  603 11.2 Three-Phase Connections  456 Summary  606 11.3 Source/Load Connections  457 Problems  606 11.4 Power Relationships  466 Chapterfi fteen 11.5 Power Factor Correction  471 Fourier Analysis Techniques 617 Summary  475 Problems  475 15.1 Fourier Series  618 15.2 Fourier Transform  641 Chaptertwelve Summary  651 Variable-Frequency Network Performance 482 Problems  651 12.1 Variable Frequency-Response Analysis  483 12.2 Sinusoidal Frequency Analysis  491 Appendix 12.3 Resonant Circuits  500 Complex Numbers 659 12.4 Scaling  521 12.5 Filter Networks  523 Index 666 Summary  534 Problems  535 Chapterthirteen The Laplace Transform 543 13.1 Definition  544 13.2 Two Important Singularity Functions  544 FM.indd viiiFM.indd viii 21/11/14 11:11 AM21/11/14 11:11 AM'; my $regex = qr/(1\.\d+)\D+?(?:(\S+)\s+)+?(\d+)/mip; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html