Regex to check if string is of exact length 7
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I have a requirement where I need to check if a first character of a string is an alphabet (a-z or A-Z), rest all characters should be numbers (0-9) and string length should be exactly equal to 7.
I am using regex tool to achieve this and used this expression: ([A-Za-z]+)([0-9]+)
With this, I am able to solve only the first two requirements but not the third one (length = 7). Can't wrap my head around this. Any suggestions are welcome. Thanks in advance.
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
There is 2 ways to get result.
You can use Formula tool with length([Field]).
Many thanks
Shanker V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hey @shobhit_gupta Try this:
[A-Za-z]\d{6}
This states that the first character is a letter and the next 6 are numbers. As Regex Match always looks at the full string, this will only be true if the string is 7 characters long
Hope that helps,
Ollie
(if you want a more concise RegEx then:
\l\d{6}
with case insensitivity on will do the same thing)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Maybe use a formula or filter tool: you can use a REGEX_MATCH function to check the regex, then add "and length([String])=7"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
