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

/
/
gm

Test String

Code Generator

Generated Code

const regex = /\w{13}\s(.*?)\./gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('\\w{13}\\s(.*?)\\.', 'gm') const str = `Baker Mayfield has apologized to Daniel Jones. That’s good. Let’s hope that Mayfield also apologized to Lincoln Riley and Joe Castiglione. Mayfield made news this week when GQ magazine published an interview with Mayfield in which the Cleveland Browns quarterback ripped the New York Giants for drafting quarterback Daniel Jones and said his 2017 flag-planting at Ohio State was coerced by OU officials. There comes a time when young men need to grow up, and for Mayfield, that time is now. Or last year, when the Browns made him the face of their beleaguered franchise. Being interesting is good. Being provocative is OK. Being a rascal who makes enemies is silly in the hardened world of pro football. After OU won 31-16 at Ohio State on September 9, 2017, Mayfield famously planted a Sooner flag on the Ohio Stadium turf. He issued an apology a few days later – which frankly, in Mayfield’s defense, wasn’t necessary. Who cares, so long as Mayfield didn’t damage any Buckeye facilities and didn’t instigate any conflicts with fans or players? I always thought too much was made of the Oklahoma tradition of stakes-claiming, which goes back to the Land Run and is replicated in the Cotton Bowl when OU happens to beat Texas. But still, it became a big deal, OU officials – I assume athletic director Castiglione and perhaps then-president David Boren – thought an apology was in order, maybe for public relations reasons only, so Mayfield issued one. Then a few days later, Riley said that the apology was Mayfield’s idea. Maybe it wasn’t, maybe it was. Probably wasn’t, knowing Mayfield. So Riley very well could have been lying, which is a good lesson for Riley but sort of beside the point on this discussion. Riley stuck up for Mayfield. Always did, really, even after that notorious crotch-grabbing incident at Kansas later in the season. Fast forward two years, and Mayfield says that Riley was not telling the truth. Mayfield told GQ that on a scale of 1-10, his apology was “zero” heartfelt. “Zero. Absolutely not … It was an emotional game, and so after the game, I did not mean for it to be disrespectful toward any Ohio State people at all, especially not the team or the players. They’re a great team, a great program, so I didn’t mean for it to be disrespectful at all. “We do the flag thing at OU-Texas, so it was something I got caught up in. Yeah, it should’ve been something I did in the locker room. I apologize for doing it in the middle of the field.” But Mayfield doubled down on criticizing the people who supported him at OU. The people who let him get away with a one-series suspension for the West Virginia game, after the debacle at Kansas, instead of a one-game suspension that would have been the more effective discipline. “I had done so much and worked so hard to play for that school, I was just kinda ... almost embarrassed for them to tell me to apologize,” Mayfield said, according to GQ. That’s uncool. Throwing Riley and Joe C. under the bus, after both stood by Mayfield, shows a major immaturity streak in Mayfield. A really good followup question for Mayfield today is how heartfelt his apology was to Jones, the New York Giants rookie quarterback. Mayfield called Jones this week to say sorry for the things printed in GQ. “I cannot believe the Giants took Daniel Jones,” Mayfield said in the magazine. “Blows my mind … some people overthink it. That's where people go wrong. They forget you've gotta win. Either you have a history of winning and being that guy for your team or you don't.” Jones played at Duke, which had a 17-19 record with Jones at quarterback. Of course, 17-19 at Duke might be comparable to 34-6 at Oklahoma. John Elway had a losing record at Stanford. Perhaps in a self-survival move, Mayfield retreated quickly from his Jones comments, writing on Instagram that his words were taken out of context and claiming the media will do anything for internet clicks. Still, it’s hard to see how “blows my mind” could be taken out of context. It’s also ironic that Mayfield, who has begat a cottage industry of playing with a chip on his shoulder, would rip a quarterback who was not highly-acclaimed. Mayfield famously went to both Texas Tech and OU without so much as a scholarship. Mayfield has used that lack of belief by the football community – the great football state of Texas failed to recognize the talent that was right under its nose – as motivational fuel for years. And now here comes Mayfield, saying that his mind is blown because the Giants drafted Jones higher than the experts figured he would go. Quite disingenuous. It’s the second time Mayfield has run afoul of the New York football Giants. Mayfield ripped the Giant fan base after Cleveland acquired controversial receiver Odell Beckham Jr. Mayfield might be wary of frontier justice. The Browns and Giants play in 2020. NFL defenders have long memories. But the bigger issue is Mayfield’s leadership. We all admire players who aren't cardboard cutouts, players who actually say what’s on their mind instead of regurgitated comments that don’t mean anything. But Mayfield’s loose lips are not befitting an NFL quarterback leading a franchise. You can be frank without being provocative. Interesting without being incinerating. It’s time for Mayfield to grow up. `; // 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