Need a specific Javascript match regex?

If you really need to do this with a match, you can use multiple positive lookahead patterns. For example, to match a be and c in any order: p = /(?=. *a)(?=.

*b)(?=. *c)/i > 'abc'. Match(p) "" > 'cba'.

Match(p) "" > 'ac'. Match(p) null.

If you really need to do this with a match, you can use multiple positive lookahead patterns. For example, to match a, b, and c, in any order: > p = /(?=. *a)(?=.

*b)(?=. *c)/i > 'abc'. Match(p) "" > 'cba'.

Match(p) "" > 'ac'. Match(p) null.

All I needed was the regex but thanks - you rule. Fixed with: eval("/(?=. *" + aText.

Join(')(?=. *') + ")/ig")) – Haraldo Oct 10 at 15:45 I'd be interested to see this benchmarked for a fairly large value of sText especially compared with splitting it into individual regexes per word. I can't be bothered though!

This would match "like Stackoverflow" btw since it lacks word boundaries, and like contains I – Paul Creasey Oct 10 at 16:31.

Why use regular expressions when . IndexOf will do the job? Var str = $(this).text().toLowerCase(); if (str.

IndexOf('i')>=0 && str. IndexOf('like')>=0 && str. IndexOf('stackoverflow')>=0) { // ... } (Mind you, in this case the "i" search is wasted since it's contained in "like", but I assume your actual code is searching for more ordinary text.) Possible related question: JavaScript: case-insensitive search.

The text may be 500 words long(+/-) – Haraldo Oct 10 at 15:17 @Haraldo: All the more reason to avoid regular expressions. (Or was that comment meant for another answer? ) – mblase75 Oct 10 at 15:22 No I was looking at your conditions.

– Haraldo Oct 10 at 15:26.

You could just split then loop - var sText = 'I like stackoverflow'; var cText = 'stackoverflow like I'; var arr = sText. Split(' '); var match = true; for (i=0;iMatch(eval("/" + arri + "/ig"))) match= false; } alert(match); You'd need to keep efficiency in mind if you were comparing lots of words though.

I think this is what you're looking for - the key is the word boundaries. Var text = "text to match" var stringToLookFor = "I like stackoverflow"; var words = stringToLookFor. Split(" "); var match=true; $.

Each(words, function(index, word) { if(!text. Match(eval("/\\b" + word + "\\b/i"))) { match=false; return false; } }); JSFiddle example.

I added return false which will terminate the loop if a word does not match, yielding improved performance. – Paul Creasey Oct 10 at 15:32 @PaulCreasey Thanks, I updated the JSFiddle example as well. – Chris Marasti-Georg Oct 10 at 15:40 Thanks for your time - I seemed to fix it with Piet Delport's solution.

– Haraldo Oct 10 at 15:47 @Haraldo does his method give a false positive match on "like stackoverflow"? Mine does not. – Chris Marasti-Georg Oct 10 at 17:22.

As you can see, this matches the entire string. I need to match case insensitive text that contains all the words individually. So it will look for "I", "like" and "stackoverflow".

It must have all 3 words.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions