Jump to content
Sign in to follow this  
sensalim

Need regexp help

Recommended Posts

sensalim

I need a regexp that grabs street name (first word only) ignoring the street number.

Examples:

123 Fake St --> "Fake"

456 Main Ave --> "Main"

Alta Vista Blvd --> "Alta"

A street Name --> "A"

Thanks.

Edited by sensalim

Share this post


Link to post
Share on other sites
Szhlopp

I need a regexp that grabs street name (first word only) ignoring the street number.

Examples:

123 Fake St --> "Fake"

456 Main Ave --> "Main"

Alta Vista Blvd --> "Alta"

A street Name --> "A"

Thanks.

(?i)[a-z]*\s|[0-9] (.*\s|.*)

:P

Edited by Szhlopp

Share this post


Link to post
Share on other sites
sensalim

Thanks but I changed the criteria...

Here's the new one.

starts with any number or not...

then after that, anything.

I came up with this but it's not perfect...

[\s]*[^0-9]+[0-9]*

This will do except this string "39 main 2 ave"

the " ave" is not included in the first match set... and I need it to.

Any help?

Thanks.

Edit:

This might do it.

[\s]*[^0-9]+.*

What do you think?

Btw I use this website http://gskinner.com/RegExr/ to test

Edited by sensalim

Share this post


Link to post
Share on other sites
Szhlopp

Thanks but I changed the criteria...

Here's the new one.

starts with any number or not...

then after that, anything.

I came up with this but it's not perfect...

[\s]*[^0-9]+[0-9]*

This will do except this string "39 main 2 ave"

the " ave" is not included in the first match set... and I need it to.

Any help?

Thanks.

Edit:

This might do it.

[\s]*[^0-9]+.*

What do you think?

Btw I use this website http://gskinner.com/RegExr/ to test

Give me 4 cases like you did in the original post. All cases being somewhat different in how they are typed. And with each case, what you want returned :P

Share this post


Link to post
Share on other sites
sensalim

"123 main st" --> " main st"

"main dr." --> "main dr."

"440 N Claude Blvd" --> " N Claude Blvd"

"??S??" --> "??S??"

"POBox811" --> "POBox811"

"P.O. Box 555" --> "P. O. Box 555"

"39 C o r d 2 ave" --> " C o r d 2 ave"

"2605S.Reith Ln" --> "S.Reith Ln"

"123 P,O, Box 456" --> " P, O, Box 456"

"789P OBox000" --> "P OBox 000"

:P

Share this post


Link to post
Share on other sites
Szhlopp

"123 main st" --> " main st"

"main dr." --> "main dr."

"440 N Claude Blvd" --> " N Claude Blvd"

"??S??" --> "??S??"

"POBox811" --> "POBox811"

"P.O. Box 555" --> "P. O. Box 555"

"39 C o r d 2 ave" --> " C o r d 2 ave"

"2605S.Reith Ln" --> "S.Reith Ln"

"123 P,O, Box 456" --> " P, O, Box 456"

"789P OBox000" --> "P OBox 000"

:P

([0-9]*)?\s?(.*)

:P

Element 1 is the key=)

Or simpler

[^0-9].*
Edited by Szhlopp

Share this post


Link to post
Share on other sites
sensalim

Yes thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×