Background
Here is an example text:
City (PLACE) Listing information... City Two (PLACE#) Listing information... ThisCity Has some notes before... (PLACE)* Listing information... NextCity (PLACE & PLACE)* Listing information...
(Place) can have one or no #,, and they can also appear as (Place & Place)*
- also they really are always acctually acronyms <= 4 characters that's why I have the {2,4} there...
So I have the following regex
(?P<place>\([A-Z]{2,4}[*#]?(?:\s?&\s?[A-Z]{1,4})?\))
For a city I have the following regex which I got from the web, it basically accounts for all the cities, (in my dataset at least) including the multi-word cities eg New York.
(?P<city>[A-Z][a-z]{1,14}(?:[-\s.]\s?[A-Z][a-z]{1,14})?)
and putting those two together I have this rather beastly regex:
[\s\n]?(?P<city>[A-Z][a-z]{1,14}(?:[-\s.]\s?[A-Z][a-z]{1,14})?)\s?(?P<place>\([A-Z]{2,4}[*#]?(?:\s?&\s?[A-Z]{1,4})?\))
which accounts for about 75% of my cases except for the tricky ones where there is a note before the (PLACE).
For example, like:
TargetCity Here is a note. Often multi-lines. (TargetPlace) Listing...
QUESTION
What I'm trying to figure out is: How - or is it even possible - for the regex of City (Place) to account for the optional note(s) eg: City -note- (Place)?
One option I thought was to look for Places that don't have punctuation before, but this doesn't work the punctuation isn't so reliable. I think it might be a case for conditionals in regex which I haven't wrapped my head around yet.
Any help/thoughts are much appreciated, Thank you!
Here is a better sample text sample text everything is same, except the words of the listing are replaced with lorem ipsum, but the number of sentences is the same:
'Aliceville (POP#) Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Atmore (RRD+) RRD Lorem Ipsum is simply dummy text of the printing and typesetting industry. Birmingham Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.(BBB#) Lorem Ipsum is simply dummy text of the printing and typesetting industry. (NNN#) Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry. (FFFF)* Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.