Skip to content
Advertisement

Python regular expression help needed, multiple lines regex

I was trying to scape a link out of a .eml file but somehow I always get “NONE” as return for my search. But I don’t even get the link with the confirm brackets, no problem in getting that valid link once the string is pulled.

One problem that I see is, that the string that is found by the REGEX has multiple lines, but the REGES itself seems to be valid.

CODE/REGEX I USE:

JavaScript

Advertisement

Answer

First thing, the .eml is encoded in MIME quoted-printable (the hint is the = signs at the end of the line. You should decode this first, instead of dealing with the encoded raw text.

Second, regex is overkill. Some nice string.split() usage will work just as fine. Regex is extremely usefull in it’s proper usage scenarios, but some simple python can usually do the same without having to use regex’ flavor of magic, which can be confusing as [REDACTED].

Note that if you’re building regex, it’s always adviced to use one of the gazillion regex editors as these will help you build your regex… My personal favorite is regex101

EDIT: added regex way to do it.

JavaScript

result is:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement