B
B
Bogdan Bedny2017-08-06 15:43:43
JavaScript
Bogdan Bedny, 2017-08-06 15:43:43

What tool to use to parse a string from a pattern?

There is an array of strings. Any string from this array matches some pattern from the list of patterns.
You need to find a suitable pattern for the string and parse it along it, ideally with the output of the result in an object.
I thought to use the path-to-regexp library, but when performing a regular expression in the results, it is not clear how to get the value by key.
An example of a list of templates in the path-to-regexp library format:

  1. :name+([a-zA-Z]+) :surname([a-zA-Z]+)
  2. :surname([a-zA-Z]+)/:surname([a-zA-Z]+)
  3. :name([a-zA-Z\-]+) :surname([a-zA-Z]+)/:name([a-zA-Z-]+) :surname([a-zA-Z] +)
  4. :surname([a-zA-Z]+) :shortName([AZ]\.)/:surname([a-zA-Z]+) :shortName([AZ].)

String list example:
  1. Thomas Fabbiano
  2. Juan Manuel Lopez
  3. Bryan/Bryan
  4. Bryan M./Bryan M.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question