regex - Replace a word based on a pattern in Javascript -


I am converting SVG to PNG and I need to remove the angle attributes in my SVG.

  & lt; Rect fill = "# F9B24F" ry = "5" rx = "5" ng-entry-y = "{{node.rectY}}" ng-at-x = "{{node.actex}}}" Ng- Attr-height = "{{chart.height}}" ng-entry-width = "{{chart.width}}" y = "10" x = "20" height = "80" width = "160" & gt; ;  

Let me output the

  and lt; Rect fill = "# f9b24f" ry = "5" rx = "5" y = "10" x is required = "20" height = "80" width = "160" & gt;  

I am trying to convert to javascript using string replay method. I have tried the following in the console, but it is not working

If you can trust the conglomerate features

always form ng-xyz = "..." , you can do this:

  str = str.replace (/ \ Bng - [^ \ s] + = "[^"] * "/ g, '');  

If some are in a single quote, then by following with each other Replace :

  str = str.replace (/ \ bng - [^ \ s] + = '[^'] * '/ g,' ');  

Obviously this is a big "if," but SGML with regular expression If you want to manipulate the markup, it is like "if" for you.>

Example:

  var str = '& lt; rect fill = "# F9B24F" ry = "5" Rx = "5" ng-entry = "{{node. Act AI}} "ng-at-x =" {{node.actx}} "ng-at-height =" {{chart.height}} "ng-atr-method =" {{chart.width}} " Function display ("before:" + str); function display (msg) {var p = "" = "[y =" 10 "x =" 20 "height =" 80 "width =" 160 "& gt; ^ \ S] + = "[^ \ s] + =" [^ "] *" / g, ''); Display ("after:" + str) Document.createElement ('p'); P.innerHTML = String (msg) .replace (/ & amp; g, "& amp; amp;;). (/ & Lt; / g," & amp; amp; lt; "); Document.body AppendChild (p);}  


Comments