nelac123 nelac123 - 1 year ago 72
Java Question

parsing numerical address

I have been trying to parse a numerical address from a string using regex.

So far, I have been able to successfully get the numerical address (partially) from the string However I have been trying to skip over the :80/, and have had no luck.

What I have tried so far is:

Pattern.compile("[0-999].*[0-999][\\p{Digit}]", Pattern.DOTALL);

however does still includes :80

I dont know what I am missing here, I have tried to check for \p{Digit} at the end, but that doesn't do much either

Thanks for your time!

Answer Source

You are looking for a positive look ahead (?=...). This will match only if it is followed by a specific expression, the one in the positive look ahead's parenthesis. In it's simplest form you could have


Though you may want to change the [0-9\.]+ part (match 1 or more digit or full stop) with something more complete to check that you have a properly formed address

Check out where you can fiddle your expression to your heart's content until it works...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download