๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
6 messages
6 total messages Started by JimH Sun, 13 Sep 2009 01:03
[xnews] Another \b question
#235446
Author: JimH
Date: Sun, 13 Sep 2009 01:03
25 lines
1658 bytes
I'm trying to get familiar with \b, and I've hit a snag that I can't find an 
answer for.

I'm trying to match with either the word "and" or the character "&".

I created the following four lines of text to test my regexp on:

1) this & that
2) me and you
3) here, there & everywhere
4) hands and feet

When I use the regexp (and|&) it will match everywhere desired, but of course 
also gives an unwanted match on the word "hands." (I put it there 
specifically for the false match)

So I changed the regexp to:

\b(and|&)\b

Now it matches only the word "and" on lines 2 and 4, but not the "&" in lines 
1 and 3. Why?

What change do I need to make?
Re: [xnews] Another \b question
#235447
Author: Ted S.
Date: Sun, 13 Sep 2009 02:57
18 lines
1753 bytes
On 13 Sep 2009 01:03:01 GMT, JimH wrote:

> Now it matches only the word "and" on lines 2 and 4, but not the "&"
> in lines 1 and 3. Why? 
> 
> What change do I need to make?

Have you tried escaping the ampersand:

\b(and|\&)\b

I can't remember whether the & is one of the characters that needs to be
escaped with a backslash.

-- 
Ted S.
fedya at hughes dot net
Now blogging at http://justacineast.blogspot.com
Re: [xnews] Another \b question
#235448
Author: me
Date: Sun, 13 Sep 2009 03:06
37 lines
2080 bytes
JimH <nvm@nunya.biz> wrote in
news:Xns9C84D62037159hahadotdotdot@74.209.136.99: 

> I'm trying to get familiar with \b, and I've hit a snag
> that I can't find an answer for.
> 
> I'm trying to match with either the word "and" or the
> character "&". 
> 
> I created the following four lines of text to test my
> regexp on: 
> 
> 1) this & that
> 2) me and you
> 3) here, there & everywhere
> 4) hands and feet
> 
> When I use the regexp (and|&) it will match everywhere
> desired, but of course also gives an unwanted match on the
> word "hands." (I put it there specifically for the false
> match) 
> 
> So I changed the regexp to:
> 
> \b(and|&)\b
> 
> Now it matches only the word "and" on lines 2 and 4, but
> not the "&" in lines 1 and 3. Why?
> 
> What change do I need to make?
> 

Because "&" is not a word.

J
-- 
Replies to: Nherr1professor2doktor31109(at)Oyahoo(dot)Tcom
Re: [xnews] Another \b question
#235449
Author: ยปQยซ
Date: Sun, 13 Sep 2009 03:19
36 lines
1977 bytes
In <news:Xns9C84D62037159hahadotdotdot@74.209.136.99>,
JimH <nvm@nunya.biz> wrote:

> I'm trying to get familiar with \b, and I've hit a snag that I can't
> find an answer for.
> 
> I'm trying to match with either the word "and" or the character "&".
> 
> I created the following four lines of text to test my regexp on:
> 
> 1) this & that
> 2) me and you
> 3) here, there & everywhere
> 4) hands and feet
> 
> When I use the regexp (and|&) it will match everywhere desired, but
> of course also gives an unwanted match on the word "hands." (I put it
> there specifically for the false match)
> 
> So I changed the regexp to:
> 
> \b(and|&)\b
> 
> Now it matches only the word "and" on lines 2 and 4, but not the "&"
> in lines 1 and 3. Why?

Because there's no word boundary between the ampersand and
whitespaces;  neither of them are word characters.

> What change do I need to make?

\band\b|&



Re: [xnews] Another \b question
#235450
Author: JimH
Date: Sun, 13 Sep 2009 07:29
43 lines
2103 bytes
=?UTF-8?B?wrtRwqs=?= <boxcars@gmx.net> wrote in 
news:20090912221952.67063bfc@bellgrove.remarqs.net:

> In <news:Xns9C84D62037159hahadotdotdot@74.209.136.99>,
> JimH <nvm@nunya.biz> wrote:
> 
>> I'm trying to get familiar with \b, and I've hit a snag that I can't
>> find an answer for.
>> 
>> I'm trying to match with either the word "and" or the character "&".
>> 
>> I created the following four lines of text to test my regexp on:
>> 
>> 1) this & that
>> 2) me and you
>> 3) here, there & everywhere
>> 4) hands and feet
>> 
>> When I use the regexp (and|&) it will match everywhere desired, but
>> of course also gives an unwanted match on the word "hands." (I put it
>> there specifically for the false match)
>> 
>> So I changed the regexp to:
>> 
>> \b(and|&)\b
>> 
>> Now it matches only the word "and" on lines 2 and 4, but not the "&"
>> in lines 1 and 3. Why?
> 
> Because there's no word boundary between the ampersand and
> whitespaces;  neither of them are word characters.
> 
>> What change do I need to make?
> 
> \band\b|&
> 
> 
> 
> 
> 

That makes a lot of sense, thanks.
Re: [xnews] Another \b question
#235452
Author: JimH
Date: Sun, 13 Sep 2009 07:32
42 lines
1980 bytes
me@tadyatam.invalid wrote in 
news:Xns9C84EB0FCAE24metadyataminvalid@feeder.eternal-september.org:

> JimH <nvm@nunya.biz> wrote in
> news:Xns9C84D62037159hahadotdotdot@74.209.136.99: 
> 
>> I'm trying to get familiar with \b, and I've hit a snag
>> that I can't find an answer for.
>> 
>> I'm trying to match with either the word "and" or the
>> character "&". 
>> 
>> I created the following four lines of text to test my
>> regexp on: 
>> 
>> 1) this & that
>> 2) me and you
>> 3) here, there & everywhere
>> 4) hands and feet
>> 
>> When I use the regexp (and|&) it will match everywhere
>> desired, but of course also gives an unwanted match on the
>> word "hands." (I put it there specifically for the false
>> match) 
>> 
>> So I changed the regexp to:
>> 
>> \b(and|&)\b
>> 
>> Now it matches only the word "and" on lines 2 and 4, but
>> not the "&" in lines 1 and 3. Why?
>> 
>> What change do I need to make?
>> 
> 
> Because "&" is not a word.
> 
> J

It figures. 

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads