简体   繁体   English

请帮我找到正则表达式来分割我的字符串

[英]Please help me to find Regex to split my string

1. Need regex to find a string is whether enclosed by a brace , that may contains brace with in enclosed string.If Yes Then needs to stripe the 1nd and last braces. 1.需要用正则表达式来查找是否由大括号括起来的字符串,其中可能包含带有括起来的大括号的括号。如果是,则需要对第一个和最后一个大括号进行分割。 eg: {StatusData/ResponseCode,RespMessage,{ArrivalMethods/AvailableArrivalMethod/AvailableArrivalMethodName,AvailableFFMCenter}} 例如:{StatusData / ResponseCode,RespMessage,{ArrivalMethods / AvailableArrivalMethod / AvailableArrivalMethodName,AvailableFFMCenter}}

INTO StatusData/ResponseCode,RespMessage,{ArrivalMethods/AvailableArrivalMethod/AvailableArrivalMethodName,AvailableFFMCenter} INTO StatusData / ResponseCode,RespMessage,{ArrivalMethods / AvailableArrivalMethod / AvailableArrivalMethodName,AvailableFFMCenter}

2. I need a regex to find a string is whether comma separated of brace sets or not and if comma separated then it needs to split as follows wwith comma. 2.我需要一个正则表达式来查找一个字符串,该字符串是大括号集是否用逗号分隔,如果用逗号分隔,则需要用逗号分割如下。 eg: {StatusData/ResponseCode,RespMessage,{ArrivalMethods/AvailableArrivalMethod/AvailableArrivalMethodName,AvailableFFMCenter}} ,{ServiceHeaders/clientSessionKey}, {Shoppingcart/OrderId,CatalogId} 例如:{StatusData / ResponseCode,RespMessage,{ArrivalMethods / AvailableArrivalMethod / AvailableArrivalMethodName,AvailableFFMCenter}},{ServiceHeaders / clientSessionKey},{Shoppingcart / OrderId,CatalogId}

INTO 进入

1. {StatusData/ResponseCode,RespMessage,{ArrivalMethods/AvailableArrivalMethod/AvailableArrivalMethodName,AvailableFFMCenter}} 2. {ServiceHeaders/clientSessionKey} 3. {Shoppingcart/OrderId,CatalogId} 1. {StatusData / ResponseCode,RespMessage,{ArrivalMethods / AvailableArrivalMethod / AvailableArrivalMethodName,AvailableFFMCenter}}} 2. {ServiceHeaders / clientSessionKey} 3. {Shoppingcart / OrderId,CatalogId}

Regarding problem 1: that cannot be solved with a regex unless you limit the depth of the nesting. 关于问题1:除非您限制嵌套的深度,否则用正则表达式无法解决。 Read this post for an example of how to do it with a limit of 3 (and a description of how to do it for other limits). 请阅读此帖子,以获取一个示例,该示例说明了如何将其限制为3(并说明了如何针对其他限制进行此操作)。 As that example makes clear, this is a monster to do with regex; 正如该示例所表明的,这与正则表达式有关。 you're better off doing this in code if that's an option for you. 如果您可以选择这样做,则最好在代码中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM