I have some strange problems with matches, hoping that someone can shed some light.
According to Java docs:
public boolean matches () ... If the match ends, then more information can be obtained through the beginning, end, and group methods.
Some codes:
private static Hashtable<String,String> splitAddress(String address){ Hashtable<String,String> result = new Hashtable<String,String>(); Matcher m = addrLong.matcher(address); if (m.matches()) { result.put("number", m.group(1));
Here it produces:
java.lang.IllegalStateException: No match found java.util.regex.Matcher.group(Matcher.java:485) splitAddress(WebServiceHelper.java:699)
This one is strange to me. Here is some more info if this helps:
private static final String numberRegex = "[0-9]*[a-zA-Z]?"; // 123a 123 private static final String compassRegex = "N|E|S|W|NORTH|EAST|SOUTH|WEST|NORD|EST|SUD|OUEST"; private static final String typeRegex = "STREET|ST|DRIVE|DR|AVENUE|AVE|AV|ROAD|RD|LOOP|LP|COURT|CT|CIRCLE|LANE|LN|BOULEVARD|BLVD|CRESCENT|CR"; addrLong = Pattern.compile("(" + numberRegex + ")\\s(.*)\\s(" + typeRegex + ")\\s?(" + compassRegex + ")?");
The input string I tested is "12 CLARE ST E"
Thanks!
Edit: Sorry, I inserted my addrShort declaration instead of my addrLong
Edit2: I know that naming conventions are being violated. I did not write this part, I swear.
UPDATE:
Successfully executed as a separate function.
Any ideas why it will break in tomcat environment?
I will see if I can find anything that can affect this, but my addrLong is my only static variable and is not used anywhere else.
It drives me crazy. I even tried:
Pattern p = Pattern.compile("(" + numberRegex + ")\\s(.*)"); Matcher m = p.matcher(address); if (m.matches()) { result.put("number", m.group(1));
in my server environment and it does not work.
UPDATE 2
It even works great when it is alone in the servlet. I'm at a dead end. Any hints or ideas are greatly appreciated.
UPDATE 3
Screw it, I just move the function to another class. Thanks for your help @ mjg123, you have a well-deserved check mark.
It will bother me forever ...