DEV Community

loading...

Discussion on: What I Learned From Bombing An Amazon Coding Assessment

Collapse
awwsmm profile image
Andrew (he/him) Author

Yeah, sometimes it just makes sense to use regex, especially when looking for patterns in text. It's easier to say "look for \([0-9]{3}\) [0-9]{3}\-?[0-9]{4}" than:

  1. look for a ( character, if you find one, check that
  2. the next character matches any of 0, 1, 2, ...
  3. the next character matches any of 0, 1, 2, ...
  4. the next character matches any of 0, 1, 2, ...
  5. the next character is a ) character...
  6. ...
  7. ...
  8. ...