0

In a short answer question in Google Forms, I have set data validation to Regular Expression with the condition of "Matches" to:

(MS|MP|PH)[0-9]{5}|Faculty

I want something like "MS18057" (etc.) or "Faculty" to be entered by the user. But in the form, I can enter "xyzFaculty" (etc.), and it seems that the condition "Matches" is behaving like "Contains."

I tried the same by removing the |Faculty portion and I was able to enter "MS18057" (etc.) only as the answer. So it worked fine without |. Why is it so?

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
Big Brother
  • 107
  • 1
  • 9
  • 2
    You could try using anchors `^(?:(?:MS|MP|PH)[0-9]{5}|Faculty)$` to prevent getting a partial match. https://regex101.com/r/a5Bdc0/1 – The fourth bird Feb 09 '20 at 09:46
  • I understand that regex will match the specified text even if there are extra characters. What I don't understand is that in Google Forms "Matches" and "Contains" are two different options and that "Matches" by default should match to the exact text? – Big Brother Feb 09 '20 at 10:16
  • I have never used forms before. I just created a test form and it seems that that is the case. If you want to use contains you could use word boundaries `\b(?:(?:MS|MP|PH)[0-9]{5}|Faculty)\b` https://regex101.com/r/GDDnOy/1 This [page](https://support.google.com/docs/answer/3378864?hl=en) contains some examples. – The fourth bird Feb 09 '20 at 10:52

1 Answers1

0

You should use the "Matches" condition and set the RegEx as ^((MS|MP|PH)[0-9]{5}|Faculty)$

Google Forms RegEx

Amit Agarwal
  • 10,910
  • 1
  • 32
  • 43