469,642 Members | 1,221 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,642 developers. It's quick & easy.

how to match this regexp?

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

Nov 24 '06 #1
9 1225
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')}

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 24 '06 #2
Randy Webb escreveu:
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)
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
-------------------------
http://www.jsfromhell.com
Nov 24 '06 #3
Jonas Raoni wrote:
shellon said the following on 11/24/2006 5:32 AM:
I want to match a string that not ended with the string
"welcome", how do write the RegExp?
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.

--
Bart

Nov 24 '06 #4
Bart Van der Donck escreveu:
Jonas Raoni wrote:
>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.
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
-------------------------
http://www.jsfromhell.com
Nov 24 '06 #5
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
>

Jonas Raoni Soares Silva
-------------------------
http://www.jsfromhell.com
Nov 24 '06 #6
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 :]
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Nov 24 '06 #7
Jonas Raoni wrote:
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
>
Nov 24 '06 #8
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 Raoni wrote:
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
Nov 26 '06 #9
In comp.lang.javascript message
<11**********************@14g2000cws.googlegroups. com>, Sat, 25 Nov 2006
19:08:32, shellon <zh*********@gmail.comwrote:
>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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/ Old RC FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 26 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike | last post: by
6 posts views Thread by Mark Findlay | last post: by
2 posts views Thread by brad | last post: by
6 posts views Thread by EXI-Andrews, Jack | last post: by
11 posts views Thread by Flyzone | last post: by
3 posts views Thread by Happy Face | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.