RedCat
RedCat

Reputation: 51

regular expression

This regular expression /^(?:([A-Za-z])(?!\1))*S(?:([A-Za-z])(?!\1{2})){3,30}\ not working. Why?

I need a string:

E.G.

Upvotes: 1

Views: 65

Answers (1)

Tranbi
Tranbi

Reputation: 12731

Look if it satisfies your requirements:

^(?:([A-Za-z])(?!\1))(?!.* .* )(?:([A-Za-z ])(?!\2{2})){2,29}$

Your reference to the second captured group was wrong: \1 instead of \2. Other than that I excluded spaces in the second negative lookahead. I also fixed the length since the quantifier doesn't apply to your first group.

You can test it here https://regex101.com/r/Y1AT1L/1

Upvotes: 1

Related Questions