且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式来查找和替换冒号内的表情符号名称

更新时间:2023-02-22 13:52:48

我建议使用

:[^:\s]*(?:::[^:\s]*)*:

请参见 regex de mo 。它与 :(?:[^:\s] | ::)*: ,但效率更高一些,因为(?:.. | ...)* 部分是展开

See the regex demo. It is the same pattern as :(?:[^:\s]|::)*:, but a bit more efficient because the (?:..|...)* part is unrolled.

详细信息


  • -冒号

  • [^:\s] * -除以外的0多个字符:和空格

  • (?:-一个未捕获的量​​化组的开始:


    • :: -双冒号

    • [^:\s ] * -除和空格

    • : - a colon
    • [^:\s]* - 0+ chars other than : and whitespace
    • (?: - start of a quantified non-capturing group:
      • :: - double colon
      • [^:\s]* - 0+ chars other than : and whitespace