我希望有人能帮助我设计一种模式,严格按照三个^的字符序列(即^^^ )拆分字符串
Input: Sample-1^^^Sample-2
Output: String 1: Sample-1 and String-2: Sample-2我尝试过\\^\\^\\^,它在快乐的道路上工作得很好。但是如果我给它一个类似这样的字符串:
Input: Sample-1^^^^Sample-2我得到的输出是:
String 1: Sample-1
String-2: ^Sample-2我也尝试了(\\^\\^\\^)模式,但没有成功。
发布于 2018-08-29 03:02:18
在这种情况下,您需要与one or more文字^字符匹配的\^+ (regex demo):
String[] output = input.split("\\^+");或者,如果您只想匹配文字^字符的3 or 4,则可以使用:
String[] output = input.split("\\^{3,4}");或者,如果你想匹配文字^字符的3 or more,你可以使用:
String[] output = input.split("\\^{3,}");https://stackoverflow.com/questions/52064635
复制相似问题