Regular expression replace a word by a link

后端 未结 7 2404
走了就别回头了
走了就别回头了 2020-12-18 11:51

I want to write a regular expression that will replace the word Paris by a link, for only the word is not ready a part of a link.

Example:

    i\'m l         


        
7条回答
  •  [愿得一人]
    2020-12-18 12:28

    Traditional answer for such question: use a real HTML parser. Because REs aren't really good at operating in a context. And HTML is complex, a 'a' tag can have attributes or not, in any order, can have HTML in the link or not, etc.

提交回复
热议问题