Snap | Phone | Regex Parser
Anonymous User
3109

Implement a simple regular expression parser:

  1. Write a function that will parse a regular expression pattern and return an object that defines the operation for our regular expression pattern matching.

Pattern Syntax:

== Character matchers:

  • . Matches any character
  • \s Matches a space or tab character
  • \ Treats the following character as a literal, eg . matches a single period
  • All other characters are treated as literals.

== Modifiers (only appear following matchers):

  • + Match at least one or more of the preceding matcher
  • * Match zero or more of the preceding matcher

Example:
Pattern: "..+, hello world!\s*"

The parsed form should be an array of tuples which describe the matcher along with any modifiers on that matcher.

General form for parsed input: [(MatcherType, Modifer)]
Example: [(AnyCharacter, ONCE), (AnyCharacter, ONE_OR_MORE), ...]
Example: [(Character('h'), ONCE), (AnyCharacter, ONE_OR_MORE), ...]

Comments (2)