Pattern for a regular expression

peispud
peispud used Ask the Experts™
on
Hi.

I would like some help with a pattern for a regular expression.   The string that I need to find will always have 3 or more "/" characters in the string surrounded by alphanumeric characters.   By that rule, the first or last character cannot be "/".

Between each "/" character, there would be a number of alphanumeric characters but the number of characters and their composition of those characters does vary.

There are no spaces in the string. All the characters are numbers or letters.  By example the string being sought might look like the following.

204A/abcd23/1124343/abc53/213c

 Thank you for your help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Developer
Commented:
(?:\w+[/]{1}){3,}\w+

Open in new window

translates as
match the following expression but don't capture it
(
Alphanumeric, one or more repetitions
A / character, exactly once
)
the above group at least 3 times followed by
Alphanumeric, one or more repetitions

Or...
^((?:\w+[/]{1}){3,}\w+)(?![/])$

Open in new window

This is a full string match and will only produce a match if the above conditions are met AND
 - the entire string matches
 - the last character in the string is not a / character
peispudTech

Author

Commented:
Perfect!   You gave me two great answers with explanation.  

Thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial