说明
^(?=(?:(?:(\S+))\s+){4})(\S+-)01(?=\s)
** 要更好地查看图像,只需右键单击图像并选择在新窗口中查看
此正则表达式将执行以下操作:
- 向前看,将 COL4 中的值捕获到捕获组 1 中
- 匹配 COL1 中的前导字符直到最后一个
-01
- 将 COL1 中的值替换为前导字符,后跟 COL4 中的值
示例
现场演示
示例文本
Col1 COL2 COL3 COL4 col5
ABHS-SMH-4OZ-01 EA CS 12 1
ABHK-SMH-01 EA CS 24 1
更换后
Col1 COL2 COL3 COL4 col5
ABHS-SMH-4OZ-12 EA CS 12 1
ABHK-SMH-24 EA CS 24 1
说明
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
(?: group, but do not capture (4 times):
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
\S+ non-whitespace (all but \n, \r,
\t, \f, and " ") (1 or more times
(matching the most amount
possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ")
(1 or more times (matching the most
amount possible))
----------------------------------------------------------------------
){4} end of grouping
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
\S+ non-whitespace (all but \n, \r, \t, \f,
and " ") (1 or more times (matching the
most amount possible))
----------------------------------------------------------------------
- '-'
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
01 '01'
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------