0

I have performance problems with ng-pattern on a textarea input.

I have a Regex expression to simply check if the code contains script, image or iframe tag. If I paste a script with multiple lines, after a certain size the entire input and page becomes unresponsive. At a certain point the entire browser tab dies.

Regex:

/^.*(<(img|iframe|script)( [^<]*)*>).*/m

Stackblitz for reproduction: https://stackblitz.com/edit/angularjs-btrpfi?file=home%2Fhome.html

Code I currently pass for testing:

<!-- Begin test script -->
<script type="text/javascript">
    var test = 123;
    var b = 24;
    var c = 22;
    var f = 56;

Steps to reproduce: Just add more lines and random content - doesn't really matter.

Any ideas how to get the multi line regex running? I'm aware in this simple case I can use a different approach to check for the tag inclusion compare to the multi-line regex approach, the original setup is a little more complex.

3
  • 2
    ( [^<]*)* is a killing type of subpattern, do not use adjoining patterns that match the same text in a indefinitely quantified group. Commented Nov 2, 2018 at 14:15
  • 1
    Just simplify your regex and make it this /^.*(<(img|iframe|script)[^>]*?>).*/m Commented Nov 2, 2018 at 14:17
  • thanks for your response. if you want you add an answer, I'll gladly accept it. Commented Nov 5, 2018 at 7:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.