Josh Allen
Josh Allen

Reputation: 997

Regular expression matching length and letters

I need a regular expression to match up to a couple criteria.

the string needs to be 8 characters long, and can only have the following letters in it: urdl.

I think it'd be something similar to /(.{8}('u')('r')('d')('l'))/

Can you help me out?

Upvotes: 0

Views: 102

Answers (2)

Mike Panter
Mike Panter

Reputation: 489

In C# you can use "^[urdl]{8}$", which ensures that the length is exactly 8 characters (and no more and no less). The "^" means the beginning, "$" represents the end, and there are 8 characters - "{8}" which each match one of the letters in the set "[urdl]".

Upvotes: 2

garnertb
garnertb

Reputation: 9584

Regex has some different flavors but in python you could use: '[ulrd]{8}' as your expression.

Upvotes: 2

Related Questions