Hi all:
I want to match a string that not ended with the string
"welcome", how do write the RegExp? Appreciate your help! 9 1362
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.substri ng(string2.leng th,string2.leng th-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.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
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.substri ng(string2.leng th,string2.leng th-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
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
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
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
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
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
>
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\.c om\//) &&
!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
In comp.lang.javas cript message
<11************ **********@14g2 000cws.googlegr oups.com>, Sat, 25 Nov 2006
19:08:32, shellon <zh*********@gm ail.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\.c om\//) && !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\.c om\/[^\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.c om/faq/ Old RC FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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"
|
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"
RegExp re = Word2;
if (re.Find(Word1))
|
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 expression specified....but the question is
how do i search for and get all or a number of specified matches within an
arbitrary long string. e.g
for example this is my reg exp i am using:
@"^-*-$" which will match any string within two...
|
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 Python, and
since I am new to javascript they are even harder. Well here's the
string, thanks for any and all help I receive.
document.URL.match(/^(.+?)(?:\?(?:(.*?)@)?(.+))?$/)
|
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 engine doesn't exaust all the
| |
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 consume a's at the expense of the string not matching
|
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 response. A very strange effect (and I can't find where
I've done something wrong) is that regexp matches in this function fail
on every second call.
|
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 printable char)two:(any printable char)one(any printable char)
Example:
Apr 30 00:00:09 v890neg0 two: findings:
blablabla
|
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 the hard coded regular expression.
but if I set $text to 12499, it will return 1 for a match.
$text = str_repeat('*', 12499);
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |