Engineering Question I am looking out for good P...
# random
r
Engineering Question I am looking out for good Parser libraries Basically want to parse email bodies & extract specific key values from it for eg: consider email body like
Copy code
First Name: {{first_name}} 
Last Name: {{last_name}}
The parser should be able to extract those values first_name: abc
e
Why not build one using regex and Python?
r
That will be my last solution Checking to see if there are any lib that makes it easier instead of me writing regex avoiding that
c
if the structure is guaranteed to be like that, yaml parser would work
h
what language are you using? There are a couple of different approaches possible: 1. Use a parser-generator. This is the most flexible way, but requires a lot of wrangling. 2. You can write a custom parser if your input data has a uniform structure, like key value pairs separated by a delimiter.
1
r
Using python And yeah it's expected in a structure
h
Just use simple string manipulation then
a
Writing a parser is perhaps the best idea. It can be modified as you want according to the structure rather than depending on a library.
2
r
Got it, Seems like using regex is inevitable at some stage
c
Since, you have mentioned the language Python, I would recommend you to take a look at django’s template parsing: https://docs.djangoproject.com/en/3.2/_modules/django/template/base/
👍 1
That will help you in regex as well as it will also help in considering edge cases and better way to write a parser. As it is battle tested and used by many people you can trust it
h
You can use pyparsing to create custom parsers with ease. https://pypi.org/project/pyparsing/
👍 1
r
Thank you everyone for your response It helped