Click here to Skip to main content
15,113,295 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,
I'm looking for a regular expression to pull reverse addresses out of a text file.

Sample String:

"123 Here is a sample string 123 234 456 567 and the string keeps going 123 234 456 567 and still going 789 232 111"

So, from this I would need anything in the format 2 or 3 Words + Number.

Correct matches would be:

Match 1: sample string 123
Match 2: string keeps going 123
Match 3: and still going 789

I believe I am close by using this as my regular expression:

"^([a-zA-z]+|[a-zA-z]+/s+[a-zA-z]+)+/s+[0-9]$"

However, still not getting results. Any ideas?

Thanks in advance,

Suraci.
Posted
Comments
Suraci7 2-Sep-10 3:48am
   
Please forgive me. Correct match for match 1 is:

Match 1: a sample string 123
LittleYellowBird 2-Sep-10 4:56am
   
Hi, I think it would help if you explained what a, zA, z and s are. How does your expression relate to the string you are trying to analyse? Just a suggestion. :)

1 solution

I used this[^] to build the expression, so you might want to tweak it a bit depending on the specific RegEx implementation (it works on the site I mentioned :) ):

(\s[a-zA-Z]+){3}\s[0-9]+

Or if {3} dosn't work:

(\s[a-zA-Z]+\s[a-zA-Z]+\s[a-zA-Z]+)\s[0-9]+
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900