haven't really looked at your examples, but I have to ask one question...
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?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Thanks to both Fred & Harsha for your suggestions.
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:
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.
Joined: Jul 18, 2011
I need a regex that make digits mandatory while the rest are optional.
& while we are at it could you guys also tell me regex for fishing out strings from text such that it doesn't contain any space,newline,tabs,etc & the full stops.....
i know split method fish out line feeds & whitespace with "//s" but what about the dot.
i am doing Java.
output should be:
"ye shall know the truth & the truth shall set you free..."
Joined: Oct 20, 2006
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.