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:
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.
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
Post a Comment