首页 > 解决方案 > regex capture group help netsuite/oracle

问题描述

I have played around on regex101 for a while now and can't figure this out and maybe it is because of the version of regex used in NetSuite. On regex101 using the string below it highlights the part I want as group 1, but results in nothing in NetSuite.

I have tried: (?:,[^,]+,?){2}(,[^,]+,?) to try and get the value between the 3rd and 4th commas out of this data set:

+000000006 06:23:15.291450,W-CHEVLPFULL-LP | ,+000000006 06:23:15.291450,W-CHEVUS | ,
+000000044 08:09:52.291450,W-ADITIVOSSM-SM | KM8014,+000000044 08:09:52.291450,W-CHEVLPFULL-LP | KM8014,
+000000125 00:53:18.291450,W-ADITHPSMFULL-HP-SM | ,+000000125 00:53:18.291450,W-ADITIVOSSM-SM | ,
+000000138 05:08:01.291450,W-ADITHPSMFULL-HP-SM | KM8512,+000000138 05:08:01.291450,W-EMPTYAVAILABLE | KM8512,
+000000138 05:20:45.291450,W-ADITIVOSSM-SM | ,+000000138 05:20:45.291450,W-EMPTYAVAILABLE |

Which would be:

W-CHEVUS | 
W-CHEVLPFULL-LP | KM8014
W-ADITIVOSSM-SM | 
W-EMPTYAVAILABLE | KM8512
W-EMPTYAVAILABLE |

I have tried other 'non capturing groups' and had strange results which leads me to think it isn't supported or I'm using them incorrectly.

Any help would be greatly appreciated. Thanks!

标签: regexnetsuite

解决方案


也许您可以使用单个捕获组和一个锚来断言字符串的开头。您的价值将在第一个捕获组中

^[^,]+(?:,[^,]+){2},([^,]+)
  • ^字符串的开始
  • [^,]+匹配 1+ 次不是逗号
  • (?:,[^,]+){2}重复 2 次匹配逗号,然后 1+ 次不是逗号
  • ,匹配第三个逗号
  • ([^,]+)在第 1 组中捕获匹配 1+ 次而不是逗号

正则表达式演示


推荐阅读