Really thorough run through of regex, such a useful feature once you know it!
Just as a heads up, your examples in your character groups section are a bit confusing. I think you've maybe missed the square brackets in the final two examples:
// Without character group
"abcdefghijklmnopqr".match(/defghij/g);
// ["defghij"]
// With character group
"abcdefghijklmnopqr".match(/[defghij]/g);
// ["d", "e", "f", "g", "h", "i", "j"]
// Without character group
"1234567890".match(/4-9/g);
// null
// With character group
"1234567890".match(/[4-9]/g);
// ["4", "5", "6", "7", "8", "9"]
With that said, the error shows how seemingly subtle changes can make a huge difference with regex, which is often where it becomes a bit tricky!
When I'm dealing with regexes that need to go into production code, I'll often set them up in a tool like Regex 101 and then use various different input strings (with multilines, odd characters etc) to check it's battle tested. I'll often then be able to put these into a unit test so the regex continues to work as expected in the long term.
Great tutorial once again!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Really thorough run through of regex, such a useful feature once you know it!
Just as a heads up, your examples in your character groups section are a bit confusing. I think you've maybe missed the square brackets in the final two examples:
With that said, the error shows how seemingly subtle changes can make a huge difference with regex, which is often where it becomes a bit tricky!
When I'm dealing with regexes that need to go into production code, I'll often set them up in a tool like Regex 101 and then use various different input strings (with multilines, odd characters etc) to check it's battle tested. I'll often then be able to put these into a unit test so the regex continues to work as expected in the long term.
Great tutorial once again!