I’m trying out a very simple regex, and my question is that I just need to make sure that if is one of the following terms is found in the data-title of my div, then the alert says so: Person Name, Email, Title and a few more strings.
I’ve used a few combinations but I haven’t been able to do it… so I’ve made a fiddle here: jsfiddle, I’ve just removed my regex attempts apart from the |, so I’ve left only the main phrases I want to catch. Could someone please help? I know it could be done using substring or indexOf but I want to do it with regex.
JS:
title = $('#me').attr('data-title');
alert(title);
if (title.match((Person Name) | (Email) | (Message) | (Company) | (Mobile) | (Title))) alert("It matched!");
HTML:
<div id='me' data-title='en_Person name'>MY NAME IS FOO</div>
http://jsfiddle.net/aLdWD/2/
You need to wrap regular expressions in the
/delimeter; what you had was just a syntax error. Also you need to use theimodifier to ignore case (you had “Person name” in the title but “Person Name” in the expression). The parentheses don’t add anything.