Check variation of words in a sentence with RegExp

1

I have a code that verifies phrases that the user types and was tried more without much success, make a code using RegExp to verify that the user entered a certain phrase without or with variations of words. / p>

Example: "I use Facebook" or "I use Google"

The two sentences are almost identical with only one variation of the word.

I wanted this code to verify that the user entered this phrase with possible default variations.

I do not understand much about, but I think it would look something like this:

"Eu uso o google".exec( /^Eu uso o [google, facebook]$/i );
    
asked by anonymous 30.07.2014 / 05:17

1 answer

1

The .exec() method is in reverse, it must be regex.exec(str) , and in case you only want a boolean you can use .test() . However you can take the $ and do so:

var str = "Eu uso o google";
var regex = /^Eu uso o [google, facebook]/i;
var teste = regex.test(str); // true

Example: link

A site I usually use to test regular expressions is: link

    
30.07.2014 / 10:56