DEV Community

Cover image for Prism and Some Thoughts On Regex
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer

Posted on

Prism and Some Thoughts On Regex

i was browsing the site of prism.js when i saw this:

Parsers fail on incorrect syntax, where regular expressions keep matching.

the author was explaining one of the decisions taken namely to use regular expressions. but, the statement above is flawed for two points

  • Parsers fail on incorrect syntax
  • regex have no link to parsers

Do Parsers Fail On Incorrect Syntax?

that one is an easy one. can't we write parsers that keep going? this point is cleared by the second one

Are Regex Different From Parsers?

regex are just another way to describe patterns be it large pieces of string like a language or just a simple piece of string like finding an email address in a paragraph.

books on compiler theory sometimes use regex instead of BNF to describe elements. looking from another angle, how does regex work, is it some native language to the computer? no, a parser has been written to understand regex and accomplish the underlying matching.

Conclusion

natural language parsing offers some interesting reflections from time to time. here is a case of the author trying to say: 'it works, let it be'

Top comments (0)