Help with regular expression


I am looking for a pattern of numbers in a text string and trying to come up with the right regex to find matches.

The pattern is at least two sets of 4 digit numbers separated by a space. The pattern can be preceded by nothing (beginning of text string), a space, period, colon, semicolon, comma and followed by the same or nothing.

Examples of matching strings:

2710 9843 9343;

LTD 1234 4335 34555532-and this or that


Strings that should not match:

AF1234 3456-23456

12345 3445-1234-1234-1234 2345s


I am using MATCHES (but am open to other suggestions) and have this expression so far, but it doesnt work in all cases:

MATCHES(#myString;".*\\d\\d\\d\\d \\d\\d\\d\\d[\\W\\s ]*")


MATCHES(#myString;".*\\d{4} \\d{4}[\\W\\s ]*")

Note that I''m not handling the pre and post pattern non alph characters mentioned above.

Your help would be much appreciated!

Tony Schullo

1 comment

  • Avatar
    Joel Stewart

    Tony, here's the Regex that I would use for the pattern you've described: 

    \b\d{4} \d{4}\b

    When view this Regex in Datameer's Java escaped version, the MATCHES formula would look like this:

    MATCHES(#myString;"\\b\\d{4} \\d{4}\\b")
Please sign in to leave a comment.