Why does this work but this doesn't
-
This works without the $ but I need it to work from the end of the line not the start of the line. Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)
Not Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)$
What I'm trying to do is grab the street type from an address which works fine using just
[a-zA-z]+$
When the address is like "123 Easy Street" but it doesn't work well when there's a street direction afterwards like "123 Easy Street N". I'm trying to skip over the single character direction indicator and match "Street" whether the single character is there or not, but it's also not always "Street" as it could be avenue, crescent, drive, highway, road, etc. I think my line above will do what I need but I can't get it to work with the $ to read backwards. Any help would be appreciated!
-
This works without the $ but I need it to work from the end of the line not the start of the line. Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)
Not Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)$
What I'm trying to do is grab the street type from an address which works fine using just
[a-zA-z]+$
When the address is like "123 Easy Street" but it doesn't work well when there's a street direction afterwards like "123 Easy Street N". I'm trying to skip over the single character direction indicator and match "Street" whether the single character is there or not, but it's also not always "Street" as it could be avenue, crescent, drive, highway, road, etc. I think my line above will do what I need but I can't get it to work with the $ to read backwards. Any help would be appreciated!
-
Couple of questions. What regex flavor are you using POSIX, PCRE, .NET, Java, etc? Is this part of a compiled/interpreted program (e.g C++, C#, python), or is it part of something more like a shell script?
Keep Calm and Carry On
I'm trying to use it within Pabbly Connect, which is an integration system like Zapier or Make. I can use the following spreadsheet type formulas found here https://www.pabbly.com/spreadsheet-formulas/ and similar usually to Google sheet formulas.
-
This works without the $ but I need it to work from the end of the line not the start of the line. Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)
Not Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)$
What I'm trying to do is grab the street type from an address which works fine using just
[a-zA-z]+$
When the address is like "123 Easy Street" but it doesn't work well when there's a street direction afterwards like "123 Easy Street N". I'm trying to skip over the single character direction indicator and match "Street" whether the single character is there or not, but it's also not always "Street" as it could be avenue, crescent, drive, highway, road, etc. I think my line above will do what I need but I can't get it to work with the $ to read backwards. Any help would be appreciated!
Andrew St. Hilaire wrote:
it doesn't work well when there's a street direction afterwards like "123 Easy Street N"
Your pattern explicitly requires at least two letters at the end of the line, with a non-word character before them. "123 Easy Street N" only has one letter at the end of the line, and is therefore not a match for your pattern. NB: Your pattern could be simplified to:
(\b[A-Za-z]{2,})$
You need to consider the data you are trying to match, and come up with a pattern to match it. Given your example, you could try:
(\b[A-Za-z]{2,}\b)(\s+[A-Za-z])?$
which would match "Street" in both "123 Easy Street" and "123 Easy Street N".
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
This works without the $ but I need it to work from the end of the line not the start of the line. Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)
Not Working:
(\b[A-Za-z]{1}[A-Za-z]+\b)$
What I'm trying to do is grab the street type from an address which works fine using just
[a-zA-z]+$
When the address is like "123 Easy Street" but it doesn't work well when there's a street direction afterwards like "123 Easy Street N". I'm trying to skip over the single character direction indicator and match "Street" whether the single character is there or not, but it's also not always "Street" as it could be avenue, crescent, drive, highway, road, etc. I think my line above will do what I need but I can't get it to work with the $ to read backwards. Any help would be appreciated!
Andrew St. Hilaire wrote:
I'm trying to skip over the single character direction indicator and match "Street" whether the single character is there or not,
So match the following so it returns 'Main' in the match for any of the following 1. 123 Main 2. 123 Main View 3. 123 Main N 4. 123 Main View S
(\b[A-Za-z]+)((\s+[A-Za-z])?)$
First clause matches the street. Second clause optionally matches a single last character. Why the extra parens in the second clause? Because I prefer to always have a match for optionals. So in this case first match is street name and second match (always there) is either something like 'S' or it is empty/null. If the parens were not there then there might or might not be a second match (you would need to test for it.)