Select to view content in your preferred language

Regex not taking

502
3
03-31-2026 12:43 PM
ChaceCarpenter
Occasional Contributor

Hello, I am trying to limit an address input in Survey123 by adding a constraint . I am using the regex below to achieve this goal.

regex(., "^(\\d{1,})\\s{1,}(North|South|East|West|N|S|E|W|NE|NW|SE|SW)\\s{1,}(\\w{1,})\\s{1,}(\\w{1,})((,{1}\\s{1,})|\\s{1,})(North|South|East|West|N|S|E|W|NE|NW|SE|SW),\\s{1,}(\\w{1,}),\\s{1,}(\\w{2}),\\s{1,}(\\d{5})$")

I used this same regex in a python script with success, so the logic is correct. I'm not sure what I am doing wrong. Am I missing something?

Note: The regex should accept an address with the following format: "111 N Street St N, City, OH, 44444"

0 Kudos
3 Replies
AlfredBaldenweck
MVP Frequent Contributor

It's probably the escaped backslashes. since then it's looking for the literal text "\s" instead of the space characters.

For python, you can avoid these by using r"\s", for S123 you can just put them in.

Here's one of mine

regex(., '^(WYWY\d{9})$|^(WY[A-Z]\d*[A-Z]?)$')

0 Kudos
ChaceCarpenter
Occasional Contributor

If i'm understanding you correctly, you are saying I can replace a \s with an actual space? So my above regex would look like: regex(.,"^( [0-9]{1,}) {1,}(North|South|East|West|N|S|E|W|NE|NW|SE|SW) {1,}([[a-zA-Z0-9]{1,}) {1,}([[a-zA-Z0-9]{1,})(?:,{1} {1,}| {1,})(North|South|East|West|N|S|E|W|NE|NW|SE|SW), {1,}([[a-zA-Z0-9]{1,}), {1,}([[a-zA-Z0-9]{2}), {1,}( [0-9]{5})")

 

I also replaced \d with [0-9] and \w with [a-zA-Z0-9]

0 Kudos
AlfredBaldenweck
MVP Frequent Contributor

No, I mean you have 

regex(., "^(\\d{1,})\\s{1,}

and you should have

regex(., "^(\d{1,})\s{1,}

0 Kudos