RE: Stripping words from a string

2002-02-21 Thread Jonathan E. Paton

 --- Wagner-David [EMAIL PROTECTED] wrote:
 Though s(world .. worked w/o /, it should be written
 s/(world | how )//gi;

s/\b(world|how)\b//gi;

The \b is a word boundary, which is going to work as
expected more frequently.

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Stripping words from a string

2002-02-21 Thread Mark Anderson


 Though s(world .. worked w/o /, it should be written
 s/(world | how )//gi;

 s/\b(world|how)\b//gi;

 The \b is a word boundary, which is going to work as
 expected more frequently.

The first example doesn't work if the word is followed by a punctuation
mark.
The second example doesn't get rid of the space, which is fine for HTML, but
not for other uses.

I would suggest
$string =~ s/ ?\b(world|how)\b//gi;
but I'd love to hear further suggestions.

/\/\ark


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Stripping words from a string

2002-02-21 Thread Jeff 'japhy' Pinyan

On Feb 21, Mark Anderson said:

The first example doesn't work if the word is followed by a punctuation
mark. The second example doesn't get rid of the space, which is fine for
HTML, but not for other uses.

Well, you have to define the word-removal.  If you're removing the word at
the beginning of a sentence, TRAILING spaces must be removed, and the next
letter capitalized!  If you're removing the word in the middle or at the
end of a sentence, LEADING spaces must be removed.

That's a bit complex, no?

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Stripping words from a string

2002-02-19 Thread Wagner-David

Put the string in $_ and with 

s(world |how )//gi;

If you don't take out a space then you get a couple of spaces:
Output(no space part of check (world|how):
Hello   are you? 

Output(w/ space part of check above):
Hello are you?

Wags ;)
-Original Message-
From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 19, 2002 21:25
To: [EMAIL PROTECTED]
Subject: Stripping words from a string


Hey all,

Just wondering how I would go about stripping words from a string.

If I have a string that has the following...

$string = Hello world how are you?;

How would I go about stripping the words 'how' and 'Hello' ignoring case
each time?

Would it go something like the following...

$string =~ s/.*hello/how\//gi;

Thx,

Da

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Stripping words from a string

2002-02-19 Thread Wagner-David

Though s(world .. worked w/o /, it should be written s/(world | how )//gi;
Perl gurus, why does s(world |how )//gi w/o errors?

Wags ;)

-Original Message-
From: Wagner-David 
Sent: Tuesday, February 19, 2002 21:48
To: 'Daniel Falkenberg'; [EMAIL PROTECTED]
Subject: RE: Stripping words from a string


Put the string in $_ and with 

s(world |how )//gi;

If you don't take out a space then you get a couple of spaces:
Output(no space part of check (world|how):
Hello   are you? 

Output(w/ space part of check above):
Hello are you?

Wags ;)
-Original Message-
From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 19, 2002 21:25
To: [EMAIL PROTECTED]
Subject: Stripping words from a string


Hey all,

Just wondering how I would go about stripping words from a string.

If I have a string that has the following...

$string = Hello world how are you?;

How would I go about stripping the words 'how' and 'Hello' ignoring case
each time?

Would it go something like the following...

$string =~ s/.*hello/how\//gi;

Thx,

Da

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Stripping words from a string

2002-02-19 Thread Tanton Gibbs

s(world | how)//gi works for the same reason
s{world | how}{}gi works
The first and second set of regex delimiters do not have to be the same, so
in the first instance, the first set of delimiters is () and the second set
is //.
- Original Message -
From: Wagner-David [EMAIL PROTECTED]
To: Wagner-David [EMAIL PROTECTED]; 'Daniel Falkenberg'
[EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, February 20, 2002 1:22 AM
Subject: RE: Stripping words from a string


 Though s(world .. worked w/o /, it should be written s/(world | how )//gi;
 Perl gurus, why does s(world |how )//gi w/o errors?

 Wags ;)

 -Original Message-
 From: Wagner-David
 Sent: Tuesday, February 19, 2002 21:48
 To: 'Daniel Falkenberg'; [EMAIL PROTECTED]
 Subject: RE: Stripping words from a string


 Put the string in $_ and with

 s(world |how )//gi;

 If you don't take out a space then you get a couple of spaces:
 Output(no space part of check (world|how):
 Hello   are you?

 Output(w/ space part of check above):
 Hello are you?

 Wags ;)
 -Original Message-
 From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, February 19, 2002 21:25
 To: [EMAIL PROTECTED]
 Subject: Stripping words from a string


 Hey all,

 Just wondering how I would go about stripping words from a string.

 If I have a string that has the following...

 $string = Hello world how are you?;

 How would I go about stripping the words 'how' and 'Hello' ignoring case
 each time?

 Would it go something like the following...

 $string =~ s/.*hello/how\//gi;

 Thx,

 Da

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]