javascript - Excluding characters in group (regular expressions) -


i have issue regular expressions in javascript (i'm not pro in regular expressions matters).

for reasons don't explain, have match text in way , cannot change code deals result.

for example, want match text: mon.2014/01/01 in way obtain result: ["mon.", "20140101"] , regex , no post processing.

i tried lookaheads, excluding groups, noticed there not lookbehinds , lookarounds , didn't manage solve it.

edit: put code sample easier understand i'm doing.

function match(regexes, text) {     for(var in regexes) {         var match = text.match(regexes[i]);         if(match !== null) {              return match;             }     } } // expected result of match(regexes, "mon.2014/01/01"): ["mon.","20140101"] 

how told you, cannot change code, has done solely regex. have hint? thank much!

short answer: you can't.

if code uses string.match method, returns parts of strings matched regexp. can't embed string modifications inside match regexp, have replace.

two possible solutions work around issue:

  1. inject javascript before particular code ran, , override string.prototype.match method split regexp text 2 separate regexp's, 1 .replace , 1 .match -- in way add support in database able alter strings before matching. if no delimiter found, defaults original match method.

  2. find alternative requirement modify string. rather expecting ["mon.","20140101"], expect ["mon.","2014/01/01"].. because that's there. if need regexp match either format, that's possible, return whatever there matched on.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -