[英]How to split a String on the basis of comma
I am having a String which is a combination of comma and space now to want to get specific elements in a order How i can do that ,I am posting the String我有一个字符串,它是逗号和空格的组合,现在想要按顺序获取特定元素我该怎么做,我正在发布字符串
12:00am, 2:30am3:30am, 5:00am7:45pm,9:00pm
This is the String i am trying to split the String using这是我尝试使用的字符串拆分字符串
List<String> interviewTimingToFrom1 = Arrays.asList(interviewTime1.split(","));
But this is not working ,i just want to split 12:00am,3:30am,7:45pm in a List and 2:30am,5:00am,9:00am in a list how to do that ,please somebody help但这不起作用,我只想在列表中拆分 12:00am、3:30am、7:45pm 和列表中的 2:30am、5:00am、9:00am 如何做到这一点,请有人帮忙
You can use this regex:您可以使用此正则表达式:
List<String> interviewTimingToFrom1 = Arrays.asList(
interviewTime1.split("\\s*,\\s*|(?<=[ap]m)(?=\\d)"));
RegEx Breakup正则表达式分解
Split using:拆分使用:
\s*,\s* # comma surrounded by optional spaces on either sides
| # regex alternation
(?<=[ap]m)(?=\d) # when preceding text is am or pm and following character is a digit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.