RegEx to split formatting string in JavaScript -
I am using a JS Date Library containing a simple Unfortunately, the month should be the letter that appears in the formatting string, e.g. 'Date (' 2014-09-01 ') AsString ('dd mmm yyyy') = 01 Sep 9 9 2014 ' It is quite easy to solve; Instead, replace the 'Yy', 'mmmm', 'mmm', 'mm', 'm', 'dddd' 'ddd', 'dd', 'd', 'hh', 'min', 's']; Automatically So I need help writing this RegEx if this can not be done, please say - I am not interested in using new libraries as a solution, but solutions will be considered which are currently available This should do the following: / Code> asString () formatting syntax eg. . DD MMM yyyy production 01 January 1970. . asString () method to use the format '[DD] [MMM] [YAY]'. Although it comes from the global format string used by other methods. The only way that square brackets are needed is the asString method. []
dd / mm / yyyy = & gt; Unfortunately, RegEx is proving complicated - the result of each code is looping in [[d] [d]] / [[m] [m]] / [[yaani] [yay ]] .
var regex = / (min | y + | m + | d + | h + | s +) / g, newString = format.replace (regex, '[$ 1]') ; Tested with format "dd / mm / yyyy" , resulting in "[dd] / [mm] / [yyyy]"
Comments
Post a Comment