gpt4 book ai didi

javascript - 仅当后面跟着某个字符串时才用分隔符分割

转载 作者:行者123 更新时间:2023-12-01 01:57:34 25 4
gpt4 key购买 nike

我有一个字符串“values.component_category:monstor_client,dimensions.pool:rpool1,dimensions.env:prod,values.error_description:No content to map due to end-of-input↵ at [来源:java .io.StringReader@2ef452e5;行:1,列:1],values.incident_category:健康”

并尝试用 , 分割它,前提是它后面跟着字符串 valuesdimensions。由于中还有一个,;行:1,列:1,我想转义它。

我尝试使用正则表达式.split(/,?(values|dimensions)./)

预期输出:

[
"values.component_category:monstor_client",
"dimensions.pool:rpool1",
"dimensions.env:pord",
"values.error_description:No content to map due to end-of java.io.StringReader@2ef452e5; line: 1, column: 1]",
"values.incident_category:health"
]

最佳答案

https://www.regular-expressions.info/lookaround.html

特别是您需要使用前瞻功能,例如:,(?=values|dimensions)

关于javascript - 仅当后面跟着某个字符串时才用分隔符分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50890751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com