How to detect if string contains pattern with JavaScript:
1. input="[Lorem]foo";
2. input="[ ]";
3. input="[ipsum]foo";
4. input="[dolor]foo1";
5. input="[sit ]foo2";
6. input="[ amet]foo3";
7. input="amet]foo3";
...
Script should process input in this way:
1. string1='Lorem'; string2="foo";
2. do nothing;
3. string1='ipsum'; string2="foo";
4. string1='dolor'; string2="foo1";
5. do nothing;
6. do nothing;
7. do nothing;
...
This would be a part of script...
input = "[asd]qwe";
input2 = "qwe";
processit(input);
processit(input2);
function processit(e){
if(..???..){
alert(string1);
alert(string2);
}
else {
return false;
}
}
Thank you for your time.
EDIT: Solution must be cross-browser
IE7 +
Firefox 3.6+
Chrome 7+ ...