My experience with regex
I have always stayed far away from regex. In one of my first year computer science labs, there was an exercise ...
For further actions, you may consider blocking this person and/or reporting abuse
I would like to share my two favorites tools to create, edit, visualize and debug regex:
Debuggex.com
my favorite tool, it can make a diagram of how your regex will work, you can add multiple lines to test if the regex match the strings that you expect and also has a cheatsheet
RegExr.com
Similar to debuggex except it doesnt generate the diagram, but in my opinion their cheatsheet is cleaner and easier to find what you need.
Regex101 also seems like a great and quick site to know if your regex works!
Hey @catherinecodes , I think you've missed the greedy vs lazy matching:
Nice! I didn't learn those yet
You can achieve laziness with negated set too:
Just to nitpick, the second wildcard example should be
.*
, and your group examples will fail because you didn't capture a space (it is ice cold outside
andit is cold outside
match but notit is cold outside
)Regex is great! And not at all as hard as it looks. Although I still don't have the hang of lookahead/lookbehinds yet 😅
Good catch Ryan! Thank you! I've updated the cheatsheet ☺️
I still need some more practice as well 😅lookaheads and lookbehinds were totally new to me! I didn't know about them during my CS lab 😲
You should add a note about lookbehind compatibility. It's not available in all browsers quite yet.
github.com/tc39/proposal-regexp-lo...
tc39.github.io/proposal-regexp-loo...
I am going to bookmark the Gist version of your very wonderful cheat sheet. I look forward to using it every time I work with regex. The samples appear in a very logical progression that makes it very easy to understand and use. Thank you!
So happy you find it useful!!! ☺️☺️☺️
Very nice and brainstorming regex challenge is RegexGolf - alf.nu/RegexGolf :)
Another view on "regex games" is Regex Crosswords. Very nice idea. regexcrossword.com/
These look fun! Thanks for sharing :)
Regex = Black Magic
Convince me if not! Never sure why something works. I just don't touch it and put the script inside as many as folders possible in case some evil spirit leaks out to our world.
Hide it away!!! 😂😂😂
Lookaheads and lookbehinds would be the features closest to "if-then" logic one uses while coding.
Just finished Bonnie Schulkin's course on regular expressions on Udemy. Great course, learned a lot about regex.
Another really great resource is regular-expressions.info/
Nice post! I recommend this site too: regex101.com/
Great post, Catherine. 👏🏼👏🏼
Created a gist out of this post. 😊
Link to Gist
Thank you Sarthak! I'll link it in the post :)
Totally saving this, as I'm supposed to be learning regex next week in class!
Yay, thank you! Have fun! :)
In the ‘wildcards’ example, you’ve written
regex = /h.llo/; // the "" matches any character(s) zero or more times... matches
"hello", "heeeeeello", "hllo", "hwarwareallo"
How does it match "hwarwareallo" ? Does not the “.” indicate only one character?
If you are adding usefull regex functions at the end of the code, you could also add information on replace function taking a callback as an argument.
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
p.replace('dog', (match, matchIndex, originalString) =>{
return match+"test"+matchIndex // match based replacer
})
Another recommendation (not free though): Regular Expressions Cookbook
Love this. I wish more people would take advantage of regex, it's so powerful! I love using regex101.com since it does a great job of explaining your regex as you write it out.
+1 to regexr.com
Great site... but now you have two problems.
Awesome! I also translated one Chinese copy: gist.github.com/cxa/901e1862cd9ddf...
Cool! Thank you for this!
Thank u! It's a powerful tool!
My pleasure :)
Awesome post thank you!
Glad you like it!
Hi, useful post!
Another online regex tester: extendsclass.com/regex-tester.html
Thanks for sharing!
not free, but RegexBuddy is awesome
that alone helped me to love regexs and made it super easy to deal with complex expressions
This is excellent, thank you! I hope you don't mind, I added it (with credit) to the "Development" portion of my company's wiki for quick reference next time one of us has to use Regex!
I would add "how to reverse the sides of an equation" to this list. There are a few other handy tricks for coders, but this is the most common I can think of right now
Yes. If I understand you correctly, that would at the same time be a good example case for another detail I was about to suggest: Match-parenthesis references in the replacement.
Something like:
"a = b + c".replace(/^(.+?) *= *(.+)$/, "$2 = $1")
Sorry, but the terrible contrast with that black background makes this far too hard to read e.g. brown on black??
This is such an awesome article. thank you. There is also an article on regex for java developers. its awesome. dev.to/codechunker/introduction-to...
I'm new to RegEx so thank you very much for taking the time to make this its a big help!
Here (techgeekbuzz.com/regex-cheat-sheet/) we have also listed a complete checklist of cheat sheet, Please check.