473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1344
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike | last post by:
Hello. Is it possible to specify a variable instead of a string as argument of string.match(). Example : myString.match(/abc/i) works but how to do this : pattern = "abc"
6
by: Mark Findlay | last post by:
I am trying to figure out how to set up my reg exp search so that the search will only match on the exact word. Here is the current problem code: Word1 = "RealPlayer.exe" Word2 = "Player.exe"...
2
by: ShadowOfTheBeast | last post by:
Hello All, i have been cracking my skull on how to seach a particular reg exp match within a string? it does not seem to happen except the whole arbitrary string is the exact match of the regular...
2
by: brad | last post by:
Hello all, I'm new to javascript--not too new to a few other programming languages--and I need your help deciphering the Regexp in the following string. Regular expresions are hard enough in...
32
by: Licheng Fang | last post by:
Basically, the problem is this: 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: 'oneself' The Python regular expression...
6
by: EXI-Andrews, Jack | last post by:
the '*' and '+' don't seem to be greedy.. they will consume less in order to match a string: ('aa', 'ab') this is the sort of behaviour i'd expect from '(a+?)(ab)' a+ should greedily...
2
by: Uldis Bojars | last post by:
Hi All, I have encountered problems with JS RegExp.exec() and can't find what is the problem. Could you help me? formRequest is a function that extracts some information from XMLHTTPRequest...
11
by: Flyzone | last post by:
Hello, i have again problem with regexp :-P I need to match all lines that contain one word but not contain another. Like to do "grep one | grep -v two:" The syntax of the string is: (any...
3
by: Happy Face | last post by:
Hi, All, I encountered this strange problem while using function preg_match. The following is the php code. when I set the line: $text = str_repeat('*', 12500); preg_match will return 0 for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.