Regex Help Please - Guru required


Hope someone can help. I’m a Sys admin for a company and we’ve just bought a DLP system that I’m trying to create a custom template for. It uses Regex for the expression to search for in the data. I’m after stopping anyone sending out our user Ids.

The user ids are 8 numeric long and always begin with a 5. I’m trying to create a regex for a number beginning with 5 and 7 other numbers after it (e.g. 56784356). I’ve tried from examples and I can get the general jist of it searching for a number but not one that has to begin with a certain number.

Can anyone please help?

Many thanks.


You can try to use this website to test Regex out. It is a really great tool:

Edit: Can you explain it better, do you want to use it for a number beginning with (5), (5 or 7), (7), or (5 end with 7)?

  • If by what I think you mean, that means you just want to select numbers that ALWAYS start with a 5, if it is not a 5, then it’s ignored. Then 7 other random numbers, if it’s more than 8 digits then it’s also ignored. Then you can try something like this

I also really like regex101.

The pattern you’re describing right now is pretty straightforward, and you could work it out with just a bit of brushing up on regular expressions. The relevant part of the freeCodeCamp curriculum starts here:

For the user ids that you’re describing you would want “Match Beginning String Patterns”, “Match Ending String Patterns”, “Match All Numbers”, and “Specify Exact Number of Matches”.

You could probably go through the whole Regular Expressions section fairly quickly and it would be a totally valid thing to do during work hours, since it’s relevant research for your job as a SysAdmin.