0

Good evening,

I'm trying to regulate input on a Google Form. Since Google Forms allows me to input Regular Expressions for data validations, I've grudgingly began writing some.

What I want:

  • I want my input String to be lower or equal to 140 characters in length. Easy enough, with the RegExp: ^.{1,140}$
  • I want the input String to not contain the words cat,dog and cardiologist. So I've written a RegExp for it, using Negative lookahead: ^(?=^(?:(?!cat|dog|cardiologist).)*$).*$
  • But what if I want my String to BOTH be lower than 140 characters, and not contain cat, dog and cardiologist? How do I combine these two Regular Expressions using the equivalent of AND between the two?

Any help would be extremely appreciated. I've been trying for hours, but Regular Expressions hurt my brain.

Dimitris Sfounis
  • 2,400
  • 4
  • 31
  • 46

1 Answers1

3

Try using this:

^(?:(?!cat|dog|cardiologist).){1,140}$

Just replace the wildcard after your tempered dot with {1,140} to quantify the length. Follow the link below for a demo to a similar pattern.

Demo

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Simpler than I suspected, I was going to look for a combination of a positive lookahead for 1-140 chars and negative lookahead for the bad strings. – Barmar Nov 01 '17 at 23:31
  • @Barmar [A good read](http://www.rexegg.com/regex-lookarounds.html) about the "tempered" dot. – Tim Biegeleisen Nov 01 '17 at 23:35
  • Works great, friend-o! Thanks a lot, it was much simpler than I adicipated. I'll be sure to read up on tempered dots. – Dimitris Sfounis Nov 02 '17 at 00:02