java - Algorithm: single quote non-matching pattern -


i have problem have template like:

"tada lala @ ha on eeee (mmm d)." 

which needs passed datetimeformatter.format()

so need quote literal text like

" 'tada lala at' ha 'on' eeee (mmm d)." 

so date pattern evolve time:

"ha 'on' eeee 'tada lala at' ha 'on' mmm, d" 

i showing real code uses:

date mydate; // computed. string template = gettemplatefromdb();//" 'tada lala at' ha 'on' eeee (mmm d)." string formattedstr = datetimeformatter(date, template); 

so evolving mean template string evolved reside in database code not coupled.

so need find algorithm put literal texts in single quote leave date patterns such (eeee) alone. best performing algorithm accomplish this?

i have draft algorithm:

string myregex = "(eeee|mmm|d|...)"; arraylist<integer> positionsfound; // list populated index positions of myregex patterns located.  string[] splittedtext = mystr.split(); // " 'tada lala at' ha 'on' eeee (mmm d)."  stringbuffer sbuf = new stringbuffer();  (int = 0;i < splittedtext.length;i++) {     if (!positionsfound.contains(i)) {         splittedtext[i] = "'"+splittedtext[i]+"'";     }     sbuf.append(splittedtext[i]+" "); }  return sbuf.tostring(); 


Comments