RegEx to Reject Unescaped HTML Character

前端 未结 2 1429
野趣味
野趣味 2021-01-24 14:02

I want to restrict usage of unescaped ampersands in a particular input field. I\'m having trouble getting a RegEx to kill usage of \"&\" unless followed by \"amp;\"...or per

2条回答
  •  感动是毒
    2021-01-24 14:24

    You can match on /&(?!amp;)/ to locate any &'s not followed by &. The (?!) construction is called a negative lookahead.

    Assuming you're using a regexp engine that supports them, at any rate. I know Perl/PCRE regexps do.

提交回复
热议问题