In This Article
What Is Regex?
Regexes in a Nutshell
When Is Regex Used?
Searching Through Files, Manuals and Logs
Regex Search in a...
For further actions, you may consider blocking this person and/or reporting abuse
Check if a number is prime:
π€―
What formula is that? It's super intriguing.
It is explained here - it is indeed very interesting
Mindblowing!
Okay, I read it, and I must say it was an engaging reading that I enjoyed.
I think is a great intro for regex, I would usually think of regex more for data validation, replacement or maybe searching... but the examples here were practical.
I agree that regex comes very handy in many cases and sometimes there may be better approaches, but as a JS dev, validate and replace data with pure methods and conditionals sometime can get very verbose:
indexOf()
,includes()
, a lot ofif
,replace
,split
,replace
(again)... sometimes I would say it's necessary to use methods like these cause they provide readability to the code, but not always, in some circumstances regex can be more practical.As you may remember I don't know too much about regex so this article is very useful for me. Currently I'm working on a small JS library in which I'm using a simple regex to replace 2 words, maybe I'll send you a link when I'll publish it.
Thanks for this article, should I put another end line? π
Thanks for great feedback π
I agree that regex shouldn't be used if it isn't necessary. replace and include functions are to prefer if it can be done easily, readably and effectively :)
Ya, send me a link when it's published. Will be fun to read.
You can put another deadline at end of January I think. Cuz completely busy with other things now for the year out. Will publish some draft or small article in December and then regex one in January :)
Hello!
I didn't forgot about this but up 'til now I published the library when I thought it was going to take less time, haha.
End of January? The last time i choosed the last day of November... so this time should be more challenging π€ ... I'll put the reminder... to... January 30.
And about my small lib (that took me months to finish the initial release version), For sure I'll send you the link, where? I have an email to hello@schemetastic.com
Will be fun to see that lib :) You can send on LinkedIn (link in website) or email dennis@perssondennis.com
Haven't been able to write anything in December. But think I should be able to publish it in January :)
You did it! And I didn't forget about this! I was waiting for this article! Actually I think it was today or yesterday when I remembered about this.
No doubt I'll read this, feedback will be provided soon!
Happy to see you here :D Wasn't sure you would actually read it, but I didn't want to miss the "deadline" π
Nice post! I've got a love / hate relationship with regex in that it's very powerful but I'll confess I can never remember the syntax! I found a use the other day, not sure it quite fits your 6 categories:
blog.johnnyreilly.com/2022/11/25/a...
It's basically extracting data from a string to drive further operations. In my case you could probably get there with .substring, but this ends up being far more reliable. Nice work anyway!
The thing about regex syntax is that people tend to overuse shorthands and complicated structures that they don't need or shouldn't use. In its simplest form, you just need one type of repetition (
+
or*
), alternation (|
), character groups ([]
and.
), and parens for grouping (()
). Everything else is just syntactic sugar or needless extended functionality (e.g. backreferences or readahead).a*
is just(a+|)
(or vice-versa),a?
is just(a|)
, and so on. Understanding how a regex would work with this limited instruction set makes the more advanced syntax a lot more palatable.