我有一个字符串“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:健康”
并尝试用 ,
分割它,前提是它后面跟着字符串 values
或 dimensions
。由于中还有一个
,我想转义它。,
;行: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/