我们有零售业数据。在那里,我们需要使用转换因子(即第4列)将每个单位SKU转换为CASU SKU&S; 输入数据
We have input data for
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
我们正在尝试用Java语言编写转换/条件逻辑。
到目前为止,我们尝试使用正则表达式:
我想搜索一些东西
e.g。 " ABHS-SMH-4OZ-01"
搜索" -01"
返回" ABHS-SMH-4OZ-24"
非常感谢任何帮助
This is my regex so far
" ABHS-SMH-4OZ-01" .matches(" -01 "。); 在此先感谢。
答案 0 :(得分:2)
^(?=(?:(?:(\S+))\s+){4})(\S+-)01(?=\s)
**要更好地查看图像,只需右键单击图像并在新窗口中选择视图
此正则表达式将执行以下操作:
-01
现场演示
示例文字
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
----------------------------------------------------------------------