Best of Fluent 2012: /Reg(exp){2}lained/: Demystifying Regular Expressions

O'Reilly · 221K views · 2013 · 48:19

Open on YouTube

Python, Ruby & scripting languagesWeb developmentSoftware practice, open source & careerstalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering regex questions and when pointing newcomers to a friendly, visual way to learn regular expressions, including in the site's regex chat room.

Recommended by 6 people across 6 different months, 2013 to 2021.

What it is

A conference talk from Fluent 2012 in which Lea Verou, a W3C developer advocate, teaches regular expressions from the basics up to advanced features. She builds up examples live with visual demonstrations, aiming to make intimidating patterns readable.

What people said

Strong rec Aaron · 2015-07 · Stack Overflow · on “Translate Go Regexp to Javascript”

@rikkigibson is right, that is a monstrosity of a pattern. Better to match 99% of cases with a clear & succinct regular expression rather than wading through a pile of ascii puke that *ehem* _still_ only catches 99% of cases. Btw, fantastic presentation about ascii puke here: /Reg(exp){2}lained/: Demystifying Regular Expressions [this video]

Strong rec Steven Lambert · 2020-12 · Stack Overflow · on “Regex expression for #include statement”

Here's the solution with comments: /^!include\((['"]?)[^'")]+\1\)/ ^ - match the start of a string !include\( - match the extract string !include( (have to escape the parentheses in regex if you want to use it as a literal string) (['"]?) - create a group (unescaped parentheses) and match either a ' or " . By using ? we can make the match optional so we can also match nothing [^'")]+ - the ^ means match everything but the ' , " , and ) characters with the + meaning match more than one. That way you won't match an empty include !include() \1 - match whatever was used in group one so we don't have quotation mismatch \) - match the last closing parentheses For learning regex I highly recommend

Recommends Benjamin Gruenbaum · 2013-06 · Stack Overflow · on “Livevalidation - Regex issue”

@Guest I'm glad it helped. If it helped you consider watching this [this video] , we've seen good results with it helping new comers with regex in the regex chat room here in SO.

Recommends Stefano Ortisi · 2013-12 · Stack Overflow · on “Array check element ID with wildcard in if statement”

You can even use regular expressions: if( !/(myId)/g.test( obj[0].id.indexOf('myID') ) ) { } I can suggest you this really good playground to test you regexp: [LINK] And this talk: [this video] Regular expression can be very powerful. Maybe your case is not that hard to be managed with other tecniques but you would find regular expressions reeeally useful in the future for other problems.

Recommends nozzleman · 2016-10 · Stack Overflow · on “Extract many substrings and put them into an array in JavaScript”

Yep, this can be accomplished using RegEx fairly easy: var txt = "1x 20GP 1x 40GP 1x 40HQ 5x 45HQ 2x 20RF 5x 40RQ" var matches = txt.match(/\d+[A-Z]{2}/g); // delivers ["20GP", "40GP", "40HQ", "45HQ", "20RF", "40RQ"] The expression basically means: \d+ at least one digit [A-Z]{2} followed by exactly 2 uppercase Letters When working with Regular Expressions, I generally use a tool like [LINK] when im stuck somewhere. This might be a good place to start learning/experimenting. I would also recommend the Talk /Reg(exp){2}lained/: Demystifying Regular Expressions of Lea Verou on [this video]

Recommends Deepak D · 2021-11 · Stack Overflow · on “Print words with at least 4 consonants javascripts”

With String match() [LINK] method for pattern-matching, and Array.prototype.filter() [LINK] for conditional screening of items, we can write a concise one-liner: > const animals = ["cat", "dog", "reindeer", "penguin", "crocodile"] > animals.filter( animal => animal.match(/[^aeiou]/gi).length >= 4) ["reindeer", "penguin", "crocodile"] Do study regex as much as possible. Here are few resources: quick overview [LINK] , deatiled demo [this video]

Cites idelara · 2016-01 · Stack Overflow · on “PHP regex to find values of terms in a string”

I am trying to generate a regex that allows me to do the following: I have a string containing several terms, all which are alphanumeric and maybe some of these special characters: +.# They are separated by a comma as well. This is kind of how it looks like: $string = 'Term1,Term2,Term3,Term4'; ... And so on... (around 60 terms) I want to be able to get each term and assign it to a variable, because I want to employ a second Regex to a long string, for example: $secondString = 'This string may contain some terms, such as Term1, or maybe Term2'; So pretty much I want to be able to check if any of the terms in the first string are present in the second string. I watched the following tutorial:

Cites Brij Raj Kishore · 2017-01 · Stack Overflow · on “Confused in capturing groups and using them further”

I was watching lecture about regular expressions [this video] and at the time 14:52 [this video] she gave to write regex to match the hex codes such as #abc #f00 #BADA55 #C0FFEE So basically the syntax is -: Start with # sign The following letter can be range [a-fA-F0-9]. These letters should be exactly of either of size 3 or 6. I understood the answer /^#([A-Fa-f\d]{3}){1,2}$/g But what is wrong in mine regex using group capturing -: /^#(([A-Fa-f\d]){3}|\2{6})$/ or /^#(([A-Fa-f\d]{3})|\2{2})$/ But /^#(([A-Fa-f\d]{3})|[A-Fa-f\d]{6})$/ is working I am using this [LINK] for testing my regex. Thanks in advance