I have a regex that is correct, yet it fails in my program. Often a different set of eyes is good.
Relevant Code:
String s_mapping = ".*<MAPPING DESCRIPTION.*NAME =.*";
Pattern mapName = Pattern.compile("\"(m_.*?)\"");
String o_mapping = "";
...
if (line.matches(s_mapping)){
Matcher matcher = mapName.matcher(line);
System.out.println(line);
System.out.println(matcher);
o_mapping = matcher.group(1);
System.out.println(o_mapping);
Output
<MAPPING DESCRIPTION ="Mapping to generate the parameters file based on the parameters inserted in the table." ISVALID ="YES" NAME ="m_FAR_Gen_ParmFile" OBJECTVERSION ="1" VERSIONNUMBER ="2">
java.util.regex.Matcher[pattern="(m_.*?)" region=0,195 lastmatch=]
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: No match found
I expect to finally see m_FAR_Gen_ParmFile as my o_mapping output.
When I test at this site: http://www.regexplanet.com/advanced/java/index.html, All passes and all is well. Why does it fail in my program? and how do I fix it?
line. Please show a short but complete program demonstrating the problem - and explain what you expected to see vs what you actually saw.linecheck the output. If you follow my SysOuts, you have everything relevant