Home All Groups Group Topic Archive Search About

string split by first occurens number

Author
28 Apr 2010 1:07 PM
John Devlon
Hi,

Does anyone have a solution for the following problem:
I would like to split a string into 2 strings by the first occurense of a
number.

Example:

"Londen street 52" into "Londen street" and "52"
"New york harbor 52 dock 2" into "New york harbor" and "dock 2"

Does anyone have a solution?

Thanx

John



__________ Informatie van ESET Smart Security, versie van database viruskenmerken 5067 (20100428) __________

Het bericht is gecontroleerd door  ESET Smart Security.

http://www.eset.com

Author
28 Apr 2010 1:25 PM
Andrew Morton
John Devlon wrote:
> Does anyone have a solution for the following problem:
> I would like to split a string into 2 strings by the first occurense
> of a  number.
>
> Example:
>
> "Londen street 52" into "Londen street" and "52"
> "New york harbor 52 dock 2" into "New york harbor" and "dock 2"
>

Your second example suggests that if there is more text after the number
then the number is to be omitted from the result. Is this correct?

--
Andrew
Author
28 Apr 2010 3:16 PM
John Devlon
Yes, you are right, my mistake.
The second should be:
"New york harbor 52 dock 2" into "New york harbor" and "52 dock 2"

Sorry


Show quoteHide quote
"Andrew Morton" <a**@in-press.co.uk.invalid> wrote in message
news:83qrabF84dU1@mid.individual.net...
> John Devlon wrote:
>> Does anyone have a solution for the following problem:
>> I would like to split a string into 2 strings by the first occurense
>> of a  number.
>>
>> Example:
>>
>> "Londen street 52" into "Londen street" and "52"
>> "New york harbor 52 dock 2" into "New york harbor" and "dock 2"
>>
>
> Your second example suggests that if there is more text after the number
> then the number is to be omitted from the result. Is this correct?
>
> --
> Andrew
>
Author
28 Apr 2010 3:04 PM
Saga
Andrew brings up a goo dpoint. Your first example:

> "Londen street 52" into "Londen street" and "52"

This implies that "New york harbor 52 dock 2" should be
turned into "New york harbor" and "52 dock 2". Saga


Show quoteHide quote
"John Devlon" <johndevlonNON@SPAMMEhotmail.com> wrote in message
news:MqWBn.432$ii2.405@newsfe29.ams2...
> Hi,
>
> Does anyone have a solution for the following problem:
> I would like to split a string into 2 strings by the first occurense of a
> number.
>
> Example:
>
> "Londen street 52" into "Londen street" and "52"
> "New york harbor 52 dock 2" into "New york harbor" and "dock 2"
>
> Does anyone have a solution?
>
> Thanx
>
> John
>
>
>
> __________ Informatie van ESET Smart Security, versie van database
> viruskenmerken 5067 (20100428) __________
>
> Het bericht is gecontroleerd door  ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
Author
28 Apr 2010 3:11 PM
Family Tree Mike
On 4/28/2010 9:07 AM, John Devlon wrote:
Show quoteHide quote
> Hi,
>
> Does anyone have a solution for the following problem:
> I would like to split a string into 2 strings by the first occurense of a
> number.
>
> Example:
>
> "Londen street 52" into "Londen street" and "52"
> "New york harbor 52 dock 2" into "New york harbor" and "dock 2"
>
> Does anyone have a solution?
>
> Thanx
>
> John
>
>
>
> __________ Informatie van ESET Smart Security, versie van database viruskenmerken 5067 (20100428) __________
>
> Het bericht is gecontroleerd door  ESET Smart Security.
>
> http://www.eset.com
>
>
>
>

Depending on your answer to the question regarding keeping the 52 in the
first example, then the following regular expression should work.

(.*?)(?:\d+)(.*)

--
Mike
Author
28 Apr 2010 3:34 PM
Family Tree Mike
On 4/28/2010 11:11 AM, Family Tree Mike wrote:
Show quoteHide quote
> On 4/28/2010 9:07 AM, John Devlon wrote:
>> Hi,
>>
>> Does anyone have a solution for the following problem:
>> I would like to split a string into 2 strings by the first occurense of a
>> number.
>>
>> Example:
>>
>> "Londen street 52" into "Londen street" and "52"
>> "New york harbor 52 dock 2" into "New york harbor" and "dock 2"
>>
>> Does anyone have a solution?
>>
>> Thanx
>>
>> John
>>
>>
>>
>> __________ Informatie van ESET Smart Security, versie van database
>> viruskenmerken 5067 (20100428) __________
>>
>> Het bericht is gecontroleerd door ESET Smart Security.
>>
>> http://www.eset.com
>>
>>
>>
>>
>
> Depending on your answer to the question regarding keeping the 52 in the
> first example, then the following regular expression should work.
>
> (.*?)(?:\d+)(.*)
>

I see your reply to another post that you want the number in the second
string.  This means the reqular expression should be:

(.*?)(\d+.*)

The earlier example did not capture the number portion in the second
capture.

--
Mike