Tuesday, 15 July 2014

java - better regular expression for matching strings? -



java - better regular expression for matching strings? -

i have "moreinfo" directory has html file , other folder. searching file in moreinfo directory( , not sub directory in moreinfo) matches toolid*.the names of file same toolid],

below code snippet how writing it, in case toolid = delegatedaccess list returns 2 file (delegatedaccess.html & delegatedaccess.shopping.html) based on wide card filter(toolid*)

is improve way of writing regular look check until lastly occurring period , homecoming file matches toolid?

infodir =/users/moreinfo private string getmoreinfourl(file infodir, string toolid) { string moreinfourl = null; seek { collection<file> files = fileutils.listfiles(infodir, new wildcardfilefilter(toolid+"*"), null); if (files.isempty()==false) { file mfile = files.iterator().next(); moreinfourl = librarypath + mfile.getname(); // toolid; } } grab (exception e) { m_log.info("unable read moreinfo" + e.getmessage()); } homecoming moreinfourl; }

this end doing great comments. did string manipulation solve problem. regex not right solution it.

private string getmoreinfourl(file infodir, string toolid) { string moreinfourl = null; seek { collection<file> files = fileutils.listfiles(infodir, new wildcardfilefilter(toolid+"*"), null); if (files.isempty()==false) { (file mfile : files) { int lastindexofperiod = mfile.getname().lastindexof('.'); string fnamewithoutextension = mfile.getname().substring(0,lastindexofperiod); if(fnamewithoutextension.equals(toolid)) { moreinfourl = librarypath + mfile.getname(); break; } } } } grab (exception e) { m_log.info("unable read moreinfo" + e.getmessage()); } homecoming moreinfourl; }

java regex

No comments:

Post a Comment