Reputation: 1728
I need a regular expression to ensure that entries in a form 1) are all lower case AND 2) do not contain the string ".net"
I can do either of those separately:
^((?!.net).)*$
gives me strings that do not contain .net
.
[a-z]
only matches lower-cased inputs. But I have not been able to combine these.
I've tried:
^((?!.net).)(?=[a-z])*$
(^((?!.net).)*$)([a-z])
And a few others.
Can anyone spot my error? Thanks!
Upvotes: 1
Views: 1230
Reputation: 163217
As you are using a dot in your pattern that would match any char except a newline, you can use a negated character class to exclude matching uppercase chars or a newline.
As suggested by @Wiktor Stribiżew, to rule out a string that contains .net
you can use a negative lookahead (?!.*\.net)
where the .net
(note to escape the dot) is preceded by .*
to match 0+ times any character.
^(?!.*\.net)[^\nA-Z]+$
^
Start of string(?!.*\.net)
negative lookahead to make sure the string does not contain .net
[^\nA-Z]+
Match 1+ times any character except a newline or a char A-Z$
End of stringUpvotes: 3