Regular expressions in Impact Stack

In a few places on Impact Stack, you can do some advanced filters that use regular expressions.

  • On match-to-target and email-to-target, have a specific message based on information about the target
  • On match-to-target and email-to-target, have an exclusion based on information about the target
  • Personalised Redirects to thank you pages based on a supporter's form submission data

This page has examples of some regular expressions you might want to use or tweak.

 

Specific messages and Exclusions in match-to-target and email-to-target actions

Quick recap of Specific Messages and Exclusions

In and email-to-target or match-to-target action, Specific Messages let you set up your supporters with a template message that is relevant to their MP (or any target). So if you know that a certain MP has already agreed to meet you, you can give your supporters who live in that MP's constituency a template message that says 'Thanks for agreeing to meet' and avoid sending lots of messages to ask for a thing the MP already agreed to.

Exclusions let you tell a supporter that an action is not meant for them (maybe they live outside the UK for example). But you can also redirect them to another page based on some information about their MP. So you could have a fake Email to MP action that asked for Postcode, then set up an Exclusion for each nation of the UK and send people to a Scotland-specific action if their MP is from Scotland. More on techniques for devolved actions.

 

So if you want a specific message for or to exclude…

  • MPs from certain countries
  • MPs of certain parties
  • MPs who you've identified as having signed an Early Day Motion
  • MPs who you've identified as Ministers (or Ministers in a certain department)
  • The negative of any of the above, eg MPs who are not from England.

If you want to match on only one constituency/country/party then you can just use an is like this. No need for regular expressions.

If you want to match on multiple constituencies/parties/countries/email addresses then select matches

Examples of Regular expressions to use and edit

Paste (or edit) these examples and add them to the 'regular expression' box after 'matches.

See an explanation of the ^, $, | etc

England or Wales (the supporter entered a postcode that isn't in England or Wales)

^(England|Wales)$

Not England

^(?!England$).+$

In this case, you can also positively match the other UK nations.

^(Wales|Scotland|Northern Ireland)$

 

By MP name. Here either Diane Abbott or Adam Afriyie (the supporter entered a postcode in the constituency of Diane Abbot or Adam Afriyie)

^(diane.abbott.office@parliament.uk|adam.afriyie.mp@parliament.uk)$

Use email address or maybe constituency name instead of Salutation or Name. If there happened to be two MPs with the same name then it might not work as you expect if you matched on Name.

 

One of the Labour parties (the supporter entered a postcode in a constituency with an MP of one of the Labour parties)

^(Labour and Co-operative|Labour|Social Democrat & Labour \(SDLP\))$

Not one of the Labour Parties (you could also list out all the other parties but that would get unwieldy)

^(?!(Labour and Co-operative|Labour|Social Democrat & Labour \(SDLP\))).+$

Note the \ before the brackets either side of SDLP

 

Personalised Redirects to thank you page based on form submission

Quick recap of personalised redirects

This lets you send your supporters to different pages after they submit your form other than a default thank you page. You can choose to send people to different pages based on something they said in the form.

 

If you want to match on only one answer then you can just use an is like this. No need for regular expressions.

 

If you want to match on multiple answers then select matches or does not match

 

Example: match one of multiple answers to a checkbox

Imagine you have a survey where you ask people how they want to get involved. If they say 'donate' or 'fundraise', you want to redirect people to a fundraising page.

Enter ^(donate|fundraise)$ into the box for regular expressions in this example.

It matches on the 'key' not the 'value' from your checkbox options.

 

Example: match on year of birth

Imagine you wanted to redirect based on age.

In your form, you ask for date of birth.

In the Thank you section you would set up a redirect that looks for the year someone entered to the date of birth question.

 

Regular expressions can only match. It can't do 'less than' or 'greater than'. So we would have to list out all the years we want to match.

.*(2007|2008|2009|2010|2011|2012|2013|2014|2015|2016|2017|2018|2019|2020|2021|2022|2023|2024)

We can do 'doesn't match' to find people whose date of birth does not include one of those years.

This approach is ok as long as you're happy that it will miss people who recently turned 18.

 

Basics of regular expressions

Here is a little intro to some of the special characters used in regular expressions above.

 

^ says only match at the very beginning.

So ^West would match any constituency starting with the letters 'West' (eg West Suffolk), but it wouldn't match other constituencies where the letters 'West' are later in the name (eg Bradford West).

 

$ says match at the very end.

So West$ would match any constituency ending with the letters 'West' (eg Bradford West), but it wouldn't match other constituencies where the letters 'West' are earlier in the name (eg Cities of London and Westminster).

 

| (pipe) means 'or' so ^(Davies|Smith)$ would match where the name was either Davies or Smith. And because we have ^ and $ around it, it would not match 'Davies-Jones'.

 

?! at the start says 'make sure the country/party name/email address doesn't match any of these bits of text'

 

Have more questions? Submit a request