I need your advice on coming up with a regex that matches the following list of numbers potentially surrounded by a combination of alphabets and special characters:
Can someone confirm whether the last regex is correct? Otherwise, what would the correct regex be?
This is the address number of a public property sales report.
Thanks a lot,
Is it a requirement that you find all the possible matches in one pass? Might it be easier to have several regexes, each of which match a (possibly distinct) subset of what you want, then you combine them later?
Yes, it is a requirement to identify that it is a property number from its sequence (first number) as well as ensuring that it consists of at least one digit. Below is an example of what this input data is made up of:
Any idea on how this could be achieved?
Jack Bush wrote:Yes, it is a requirement to identify that it is a property number from its sequence (first number) as well as ensuring that it consists of at least one digit. Below is an example of what this input data is made up of:The first 2 words is the district name which can start from 1 – 3 letters or more...
Actually, it isn't. From what I can see from your original data (the one you posted in your last thread), the district ends with the first word
that contains a number as it's first character (which seems, pretty consistently, to be the start of an address).
That word seems to contain some combination of the following:
1. A house/building number, which may be suffixed with a letter (eg, '43a').
2. A range of building numbers, separated by a hyphen (-).
3. A suite or apartment number + plus a building number (or range), separated by a forward slash (/).
I reckon Fred's right. Once you've identified the first word of the address, I think you might be better off breaking down the possibilities,
maybe with String.split(), and then using individual regexes to validate/extract the actual numbers.
BTW, as far as I can see, the document is also consistent about having all that "numeric stuff" in a single word (ie, no spaces),
so if you don't need to actually parse the contents, you could simply use "[0-9][^ ]*" to get the whole word.
i know split method fish out line feeds & whitespace with "//s" but what about the dot.
i am doing Java.
output should be:
Apologies for the late reply but I have applied Fred & Winston’s suggestion of splitting each word out and match them with their respective regexes in sequences, which is working out finally. I am still at an experimental stage but it is looking good so far.
Also thank you to Hersha for kept coming up with great regex gems.
I will close this thread now since the question has been answered.
Thank you again,