dbTalk Databases Forums  

regexp_substr help, please

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss regexp_substr help, please in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Doug Miller
 
Posts: n/a

Default regexp_substr help, please - 04-29-2008 , 10:34 AM






I need to be able to pull just the last name out of a string consisting of
lastname and firstname, separated by a comma, or space, or comma and space.
Complicating matters somewhat is the fact that lastname might be something
like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
space isn't sufficient.

The closest I've come so far is
select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
but this returns only
St. L

I thought regular expression matching was supposed to be "greedy", and take as
many characters as would satisfy the pattern ("St. Louis" in this case).

What am I doing wrong?

Reply With Quote
  #2  
Old   
md
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:33 AM






On Apr 29, 10:34 am, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
I need to be able to pull just the last name out of a string consisting of
lastname and firstname, separated by a comma, or space, or comma and space.
Complicating matters somewhat is the fact that lastname might be something
like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
space isn't sufficient.

The closest I've come so far is
select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
but this returns only
St. L

I thought regular expression matching was supposed to be "greedy", and take as
many characters as would satisfy the pattern ("St. Louis" in this case).

What am I doing wrong?
These are you combos?

ln,fn|ln, fn|ln fn
l n,fn|l n, fn|l n fn

I'd start by nuking the fn. It's the last solid string and it has an
nice anchor fn$




Reply With Quote
  #3  
Old   
md
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:33 AM



On Apr 29, 10:34 am, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
I need to be able to pull just the last name out of a string consisting of
lastname and firstname, separated by a comma, or space, or comma and space.
Complicating matters somewhat is the fact that lastname might be something
like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
space isn't sufficient.

The closest I've come so far is
select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
but this returns only
St. L

I thought regular expression matching was supposed to be "greedy", and take as
many characters as would satisfy the pattern ("St. Louis" in this case).

What am I doing wrong?
These are you combos?

ln,fn|ln, fn|ln fn
l n,fn|l n, fn|l n fn

I'd start by nuking the fn. It's the last solid string and it has an
nice anchor fn$




Reply With Quote
  #4  
Old   
md
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:33 AM



On Apr 29, 10:34 am, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
I need to be able to pull just the last name out of a string consisting of
lastname and firstname, separated by a comma, or space, or comma and space.
Complicating matters somewhat is the fact that lastname might be something
like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
space isn't sufficient.

The closest I've come so far is
select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
but this returns only
St. L

I thought regular expression matching was supposed to be "greedy", and take as
many characters as would satisfy the pattern ("St. Louis" in this case).

What am I doing wrong?
These are you combos?

ln,fn|ln, fn|ln fn
l n,fn|l n, fn|l n fn

I'd start by nuking the fn. It's the last solid string and it has an
nice anchor fn$




Reply With Quote
  #5  
Old   
md
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:33 AM



On Apr 29, 10:34 am, spamb... (AT) milmac (DOT) com (Doug Miller) wrote:
Quote:
I need to be able to pull just the last name out of a string consisting of
lastname and firstname, separated by a comma, or space, or comma and space.
Complicating matters somewhat is the fact that lastname might be something
like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
space isn't sufficient.

The closest I've come so far is
select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
but this returns only
St. L

I thought regular expression matching was supposed to be "greedy", and take as
many characters as would satisfy the pattern ("St. Louis" in this case).

What am I doing wrong?
These are you combos?

ln,fn|ln, fn|ln fn
l n,fn|l n, fn|l n fn

I'd start by nuking the fn. It's the last solid string and it has an
nice anchor fn$




Reply With Quote
  #6  
Old   
md
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:52 AM



On Apr 29, 12:43 pm, yf... (AT) vtn1 (DOT) victoria.tc.ca (Malcolm Dew-Jones)
wrote:
Quote:
Doug Miller (spamb... (AT) milmac (DOT) com) wrote:

: I need to be able to pull just the last name out of a string consisting of
: lastname and firstname, separated by a comma, or space, or comma and space.
: Complicating matters somewhat is the fact that lastname might be something
: like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
: space isn't sufficient.

: The closest I've come so far is
: select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
: but this returns only
: St. L

[A-Z] doesn't match o
Here a perl test I did to check out a maybe.
@ is an array of your combos (did I get them all?)
The loop goes thru each. $1 will contain the "last name".


@s = ("mc winter, first",
"mc. winter, first",
"winter, first",
"mc winter,first",
"mc. winter,first",
"winter,first",
"mc winter first",
"mc. winter first",
"winter first",
);

foreach $x (@s) {
print qq/look at "$x"\n/;
{
$x =~ /(.*)?[, ]{1}[a-zA-Z]*$/;
print $1 . "\n";
}
}



Reply With Quote
  #7  
Old   
md
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:52 AM



On Apr 29, 12:43 pm, yf... (AT) vtn1 (DOT) victoria.tc.ca (Malcolm Dew-Jones)
wrote:
Quote:
Doug Miller (spamb... (AT) milmac (DOT) com) wrote:

: I need to be able to pull just the last name out of a string consisting of
: lastname and firstname, separated by a comma, or space, or comma and space.
: Complicating matters somewhat is the fact that lastname might be something
: like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
: space isn't sufficient.

: The closest I've come so far is
: select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
: but this returns only
: St. L

[A-Z] doesn't match o
Here a perl test I did to check out a maybe.
@ is an array of your combos (did I get them all?)
The loop goes thru each. $1 will contain the "last name".


@s = ("mc winter, first",
"mc. winter, first",
"winter, first",
"mc winter,first",
"mc. winter,first",
"winter,first",
"mc winter first",
"mc. winter first",
"winter first",
);

foreach $x (@s) {
print qq/look at "$x"\n/;
{
$x =~ /(.*)?[, ]{1}[a-zA-Z]*$/;
print $1 . "\n";
}
}



Reply With Quote
  #8  
Old   
md
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:52 AM



On Apr 29, 12:43 pm, yf... (AT) vtn1 (DOT) victoria.tc.ca (Malcolm Dew-Jones)
wrote:
Quote:
Doug Miller (spamb... (AT) milmac (DOT) com) wrote:

: I need to be able to pull just the last name out of a string consisting of
: lastname and firstname, separated by a comma, or space, or comma and space.
: Complicating matters somewhat is the fact that lastname might be something
: like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
: space isn't sufficient.

: The closest I've come so far is
: select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
: but this returns only
: St. L

[A-Z] doesn't match o
Here a perl test I did to check out a maybe.
@ is an array of your combos (did I get them all?)
The loop goes thru each. $1 will contain the "last name".


@s = ("mc winter, first",
"mc. winter, first",
"winter, first",
"mc winter,first",
"mc. winter,first",
"winter,first",
"mc winter first",
"mc. winter first",
"winter first",
);

foreach $x (@s) {
print qq/look at "$x"\n/;
{
$x =~ /(.*)?[, ]{1}[a-zA-Z]*$/;
print $1 . "\n";
}
}



Reply With Quote
  #9  
Old   
md
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:52 AM



On Apr 29, 12:43 pm, yf... (AT) vtn1 (DOT) victoria.tc.ca (Malcolm Dew-Jones)
wrote:
Quote:
Doug Miller (spamb... (AT) milmac (DOT) com) wrote:

: I need to be able to pull just the last name out of a string consisting of
: lastname and firstname, separated by a comma, or space, or comma and space.
: Complicating matters somewhat is the fact that lastname might be something
: like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
: space isn't sufficient.

: The closest I've come so far is
: select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
: but this returns only
: St. L

[A-Z] doesn't match o
Here a perl test I did to check out a maybe.
@ is an array of your combos (did I get them all?)
The loop goes thru each. $1 will contain the "last name".


@s = ("mc winter, first",
"mc. winter, first",
"winter, first",
"mc winter,first",
"mc. winter,first",
"winter,first",
"mc winter first",
"mc. winter first",
"winter first",
);

foreach $x (@s) {
print qq/look at "$x"\n/;
{
$x =~ /(.*)?[, ]{1}[a-zA-Z]*$/;
print $1 . "\n";
}
}



Reply With Quote
  #10  
Old   
Doug Miller
 
Posts: n/a

Default Re: regexp_substr help, please - 04-29-2008 , 11:56 AM



In article <4817502b$1 (AT) news (DOT) victoria.tc.ca>, yf110 (AT) vtn1 (DOT) victoria.tc.ca (Malcolm Dew-Jones) wrote:
Quote:
Doug Miller (spambait (AT) milmac (DOT) com) wrote:
: I need to be able to pull just the last name out of a string consisting of
: lastname and firstname, separated by a comma, or space, or comma and space.
: Complicating matters somewhat is the fact that lastname might be something
: like "Mc Kay" or "St. Louis" so simply grabbing everything before the first
: space isn't sufficient.

: The closest I've come so far is
: select regexp_substr ('St. Louis, Ted', '.{4}[A-Z]+') from dual;
: but this returns only
: St. L

[A-Z] doesn't match o
Yeah, I just got back from lunch and realized the same thing. Knew it had to
be something stupid like that. Thanks.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.