RegEx to split formatting string in JavaScript -


I am using a JS Date Library containing a simple asString () formatting syntax eg. . DD MMM yyyy production 01 January 1970. .

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 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.

'Yy', 'mmmm', 'mmm', 'mm', 'm', 'dddd' 'ddd', 'dd', 'd', 'hh', 'min', 's'];

Automatically []

  dd / mm / yyyy = & gt; Unfortunately, RegEx is proving complicated - the result of each code is looping in  [[d] [d]] / [[m] [m]] / [[yaani] [yay ]] .  

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:

  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]"   

/ Code>

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -