Are the angle brackets (< or>) special in a regular expression?

前端 未结 2 853
时光说笑
时光说笑 2020-12-01 20:46

I am trying to get a regex expression to accept < and > as my outside delimiters to grab all the content in between them.

so content like such

<         


        
相关标签:
2条回答
  • 2020-12-01 21:43

    You could be having a problem when you try to insert the result into HTML and the browser thinks that it is not a valid HTML tag, like <blablabla>.

    0 讨论(0)
  • 2020-12-01 21:46

    Neither < nor > are metacharacters inside a regular expression.

    This works for me:

    '<foo> and <bar>'.match(/<[^>]*>/g); // ["<foo>", "<bar>"]
    
    0 讨论(0)
提交回复
热议问题