0

I currently have a regular expression that allows for the string 'red' in lowercase, uppercase and with spaces surrounding it:

/red/i

How would this regular expression be extended to check for multiple words such as rot, rouge, red and rojo.?

I am using a Javascript plugin which does not support flags. This regex also takes the same form in JavaScript in a none literal format, how would this be extended in the same way?

^\s*[Rr][Ee][Dd]\s*$
3
  • /red|blue|green/ig regex101.com/r/hL7fZ9/1 Commented Apr 2, 2016 at 11:06
  • Is your question about case sensitivity or multi-language support? Commented Apr 2, 2016 at 11:29
  • It is about case sensitivity, checking a string that can appear in 4 different ways - then extending a validation regex in a literal and none literal format. Commented Apr 2, 2016 at 11:31

2 Answers 2

1

Try using the OR operator in your regex:

/(blue|green|red)/i
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much - as an extension to my question - I have the same regex in JavaScript ^\s*[Rr][Ee][Dd]\s*$ is there any way to extend this is the same way?
Why don't you just use /^\s(red)\s*$/i ?
The string the user enters varies on the language selected. This is the word red. I am using a JavaScript plugin which doesn't support flags. The different versions of this string are rot, rouge, red and rojo.
Post the full code relevant to your actual question.
0

There are many dialect's of regular expressions. However, in this case the following would work in most cases:

/red|green|yellow|blue/i

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.