Hi,
I'm trying to create a regexp to use in a .replace method with the followig logic:
I want to take the below string:
"some gibberish, could be anything blah blah something worthwhile"
...and return:
"new gibberish something REALLY worthwhile"
Where in the initial string 'some gibberish, could be anything blah blah' could be any text or any characters, but NOT CONTAIN the specific phrase "foo"--and up to but not including the specific phrase 'something worthwhile'.
I've tried:
So I'm basically having trouble constructing it so it will catch anything PRIOR TO 'something worthwhile' but not if that prior string includes the phrase 'foo'.
Thanks for any help,
--Jim
I'm trying to create a regexp to use in a .replace method with the followig logic:
I want to take the below string:
"some gibberish, could be anything blah blah something worthwhile"
...and return:
"new gibberish something REALLY worthwhile"
Where in the initial string 'some gibberish, could be anything blah blah' could be any text or any characters, but NOT CONTAIN the specific phrase "foo"--and up to but not including the specific phrase 'something worthwhile'.
I've tried:
Code:
var s1 = "some gibberish, could be anything blah blah something worthwhile"
var s2="some foo gibberish, could be anything blah blah something worthwhile"
var sfind = /(.*[^foo])something worthwhile/
s1=s1.replace(sfind,myfunc) //This is successful for s1
s2=s2.replace(sfind,myfunc) //this should NOT find a match since 'foo' is part of s2 prior to 'something worthwhile', but it matches and returns the same as s1
function myfunc(match,gibberish){
gibberish = "new gibberish"
return gibberish + ' something REALLY worthwhile'
}
So I'm basically having trouble constructing it so it will catch anything PRIOR TO 'something worthwhile' but not if that prior string includes the phrase 'foo'.
Thanks for any help,
--Jim