0

I have a json object that I want to display on my html page:

  this.pattern = [
      {pattern: /AA/g, backgroundColor: '#D72638'}
  ];

To do so I use json pipe like so:

<pre>{{pattern | json}}</pre>

The object is displayed on the html page correctly, but the regex does not. What can I do to be able to show it?

empiric
  • 7,825
  • 7
  • 37
  • 48
mb925
  • 137
  • 14
  • What's the supposed regex pattern to match? – Alireza Aug 24 '21 at 08:53
  • @Alireza I developed a library tool which highlights patterns in a sequence of characters. I am now working on the documentation of the tool and this is why I need to show how the json input is, so the user can understand. You can see the problem clearly here: https://biocomputingup.github.io/ProSeqViewer-documentation/#patterns (patterns section). – mb925 Aug 24 '21 at 09:04
  • why not add qutes around the regex ? – yehonatan yehezkel Aug 24 '21 at 09:57
  • @yehonatanyehezkel if I do so, the user reading the documentation will copy the json object exactly as it is, with the quotes. Giving the regex in input to the tool with the quotes is not supported and the tool wouldn't perform the pattern matching. – mb925 Aug 24 '21 at 12:34
  • @mb925 you need to search "how to escap regex string in js/ like here https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex – yehonatan yehezkel Aug 25 '21 at 13:07

0 Answers0