RegExReplace在.com之后的所有内容

时间:2013-12-30 21:00:30

标签: regex autohotkey

我正在尝试基本上将URL中的所有内容都替换为.com

之后的内容

这是我到目前为止所做的:

clipboard := RegExReplace(clipboard, "/\.com(.*$)/", "")

我对RegEx很新,所以任何有用的东西都会很棒!

这似乎现在有效:

clipboard := RegExReplace(clipboard, "\.com(.*)", ".com")

2 个答案:

答案 0 :(得分:2)

我对AutoHotKey并不熟悉,但我相信现在你用空的字符串替换整个字符串。试试这个:

clipboard := RegExReplace(clipboard, "/(.*\.com)(?:$|[/?].*$)/", "$1")

它捕获包括.com在内的所有内容,并仅保留该内容。它还确保.com是正确的而不是

  

万维网。 com puter.com

  

wwww.website.com?redirect=google .com

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
    \.                       '.'
--------------------------------------------------------------------------------
    com                      'com'
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  (?:                      group, but do not capture:
--------------------------------------------------------------------------------
    $                        before an optional \n, and the end of
                             the string
--------------------------------------------------------------------------------
   |                        OR
--------------------------------------------------------------------------------
    [/?]                    any character of: '/', '?'
--------------------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
    $                        before an optional \n, and the end of
                             the string
--------------------------------------------------------------------------------
  )                        end of grouping

答案 1 :(得分:0)

clipboard := RegExReplace(clipboard, "\.com\b\K.*")