Re: RegEx Commands
Re: RegEx Commands
- Subject: Re: RegEx Commands
- From: Arthur J Knapp <email@hidden>
- Date: Tue, 07 Aug 2001 12:46:26 -0400
>
Date: Mon, 06 Aug 2001 18:07:41 -0500
>
Subject: Re: RegEx Commands
>
From: Ken Grimm <email@hidden>
>
>> What pattern can be used to find my name when I have no idea where the
>
>> carriage return will be?
>
> "Kenneth[ \r]Floyd[ \r]Rich[ \r]Dwayne[ \r]Grimm"
>
>
>
> Alternatively, you could use the whitespace character "\s" instead of "[
>
> \r]".
>
>
OK, OK -- you got me. <grinning>
>
>
But how do I develop a pattern (for example, to isolate the names and wrap
>
in a "bold" HTML tag) to find ANY person whose insane parents decided to
>
give them 5 or more names?
I'm not sure that I understand what you mean by "ANY name", I mean,
you have to search for something, because no pattern can distinguish
between a name, a place, a thing, etc.
The following pattern will pick up all of the following names:
[A-Z][a-z]+[ \t\r]([A-Z][a-z]+[ \t\r]+)+([A-Z][a-z]+)*
BEGIN TEXT EXAMPLES:
I want to find my full name, "Kenneth Floyd Rich Dwayne Grimm"
in any given sentence.
yada yada Kenneth Floyd
Rich Dwayne Grimm yada yada.
yada yada Kenneth Floyd Rich
Dwayne Grimm yada yada.
yada yada Kenneth
Floyd Rich Dwayne
Grimm yada yada.
END TEXT EXAMPLES
A few things to notice:
[A-Z][a-z]+[ \t\r]+([A-Z][a-z]+[ \t\r]+)+([A-Z][a-z]+)*
The basic pattern is "[A-Z][a-z]+[ \t\r]", an initial capitalized
letter, followed by 1 or more lowercase letters. I specified 1 or
more to ensure that we don't pick up "I" or an "A" at the beginning
of a sentence. This unfortunatly means that this pattern cannot
be used to obtain a person's middle initial.
The basic pattern is followed by the basic pattern again, except
that we wrap it in parantheses, followed by the once-or-more symbol.
This ensures that only 2 or more capitalized names will be found.
This also helps us to ensure that we won't pick up words that are
capitalized simply because they are at the beginning of a sentence.
Finally, I include the basic pattern once more, except this time,
I don't insist that it end with 1 or more white space characters,
ensuring that the last name can be followed by a period, quote, etc.
You're replacement pattern would simply be "<b>&</b>".
>
Let me buy ya a brew...
Samual Adams, please...
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.latenightsw.com/freeware/JavaScriptOSA/