how to match this regexp?

S

shellon

Hi all:
I want to match a string that not ended with the string
"welcome", how do write the RegExp? Appreciate your help!
 
R

Randy Webb

shellon said the following on 11/24/2006 5:32 AM:
Hi all:
I want to match a string that not ended with the string
"welcome", how do write the RegExp? Appreciate your help!

var string1 = "some string with welcome but not at the end";
var string2 = "some string with welcome and also at the end welcome";
var test = string2.substring(string2.length,string2.length-7)
if (test == 'welcome')
{alert('It has welcome at the end')}
else
{alert('It does not have welcome at the end')}
 
B

Bart Van der Donck

alert("lala welcome".substr(-7).toLowerCase() == "welcome");
But I preffer using the regexp, it's more compact :b
alert(/welcome$/i.test("lala welcome"));

I prefer that too, because the former would display "false" in MSIE6
and "true" in FF1.
 
J

Jonas Raoni

Randy Webb escreveu:
shellon said the following on 11/24/2006 5:32 AM:

var string1 = "some string with welcome but not at the end";
var string2 = "some string with welcome and also at the end welcome";
var test = string2.substring(string2.length,string2.length-7)

This way it looks cutier :)

alert("lala welcome".substr(-7).toLowerCase() == "welcome");

But I preffer using the regexp, it's more compact :b

alert(/welcome$/i.test("lala welcome"));


Jonas Raoni Soares Silva
 
J

Jonas Raoni

Bart Van der Donck escreveu:
I prefer that too, because the former would display "false" in MSIE6
and "true" in FF1.

It's true, I forgot that IE was different about substr, this works on
both :]

alert("lala welcome".slice(-7).toLowerCase() == "welcome");


Jonas Raoni Soares Silva
 
M

mick white

Jonas Raoni wrote:

But I preffer using the regexp, it's more compact :b

alert(/welcome$/i.test("lala welcome"));

Of course the word "welcome" is likely to followed by a full stop ("."),
or a space(s) in a real world situation.

/welcome\.?\s?$/i

Something like that, not tested.

Mick
 
S

shellon

Thanks a lot! I'm sorry that I didn't describe my problem exactly, The
pattern I want to match is actually is :

I want to match all the pages of the site www.raphsy.com but the home
page www.raphsy.com/welcome.html

so one Regexp maybe: str.match(/^www\.raphsy\.com\//) &&
!str.match(/welcome\.html$/)

but I don't want to use two bool expression, I want to combine the two
expression in one RegExp, that's to say: how to negate a pattern(like
/welcome\.html/) in RegExp?

Appreciate your help!!



"mick white дµÀ£º
"
Jonas said:
mick white escreveu:
Jonas Raoni wrote:
Of course the word "welcome" is likely to followed by a full stop
("."), or a space(s) in a real world situation.


Yes :]
/welcome\.?\s?$/i


Maybe the "\b" will fit better :]


I concur...
Mick
 
D

Dr J R Stockton

In comp.lang.javascript message
Sat said:
Thanks a lot! I'm sorry that I didn't describe my problem exactly, The
pattern I want to match is actually is :

I want to match all the pages of the site www.raphsy.com but the home
page www.raphsy.com/welcome.html

so one Regexp maybe: str.match(/^www\.raphsy\.com\//) &&
!str.match(/welcome\.html$/)

That rejects, contrary to specification,
www.raphsy.com/banana/welcome.html
but I don't want to use two bool expression, I want to combine the two
expression in one RegExp, that's to say: how to negate a pattern(like
/welcome\.html/) in RegExp?

And does it have to be compatible with all browsers that understand
RegExps? If so, consider

OK = !!str.replace(/welcome.html/, "\u20A4")
.match(/^www\.raphsy\.com\/[^\u20A4]/)

Few modern pages will have \u20A4 anywhere, let alone in the URL.

It's a good idea to read the newsgroup and its old FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top