regex - 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!
解决方案
也许您可以使用单个捕获组和一个锚来断言字符串的开头。您的价值将在第一个捕获组中
^[^,]+(?:,[^,]+){2},([^,]+)
^
字符串的开始[^,]+
匹配 1+ 次不是逗号(?:,[^,]+){2}
重复 2 次匹配逗号,然后 1+ 次不是逗号,
匹配第三个逗号([^,]+)
在第 1 组中捕获匹配 1+ 次而不是逗号
推荐阅读
- javascript - 如何在 JavaScript 中找到最小日期?
- java - 在切换时故意使 CardLayout 中的组件不可见
- php - 没有插件的元标记中的 Woocommerce 简短描述
- c# - 范围报告 4.0.3 - 捕获屏幕截图不起作用 - c#,specflow
- php - 在 PHP 中为什么 24 % 1 等于 1,它不应该等于 0 吗?
- amazon-web-services - 保护 Lambda 的 AWS RDS 凭证
- r - 如何在 ts_plot 中添加垂直线?
- python - 拉动 excel 行以在 tkinter 中显示为网格
- java - 为什么提交的堆内存从 4G 减少到 3.86G?
- css - 网格自动列:50px 50px 20px;没有模板或网格区域