Question

I'm using Aweber's automatic email parsing for Unbounce form submissions and it seems that their default regex is a bit wonky:

They match email with \nemail:\s+(.+?)\n and name with \nname:\s+(.+?)\n

The problem is that because I'm not asking users for their name, their regex automatically grabs the next line, which is ===== FORM DATA =====, so it emails users with "Hi ===== FORM DATA =====!"

Here's what a sample Unbounce email looks like:

page_name:
page_id: 2b78ddde-e7bb-11e1-9fde-12313e00ec56
page_url: http://www1.sample.com
variant: C
email: sample@gmail.com
name:

===== FORM DATA =====

email: ["sample@gmail.com"]
ip_address: 88.253.**.**



--
The Unbounce Team
Toll Free 1-888-515-9161
support@unbounce.com
http://unbounce.com

How do I modify their regex so that it stops at the end of the line if there's no value present?

Was it helpful?

Solution

Change the name regex to the following:

\nname:[ \t]+(.+?)\n

The change here is to replace \s with [ \t], because \s will match newlines.

This will cause the match to fail if a name is not provided, if you would like it to still match but put an empty string into the group, you can use the following:

\nname:[ \t]*(.*?)\n

As noted by Evandro Silva, you can make this regex more efficient by replacing the .+? or .*? with [^\n]+ or [^\n]*, respectively.

OTHER TIPS

Try regex pattern [\n\r]name:[^\S\n\r]*([^\n\r]*)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top