[英]How to split a String on the basis of comma
我有一个字符串,它是逗号和空格的组合,现在想要按顺序获取特定元素我该怎么做,我正在发布字符串
12:00am, 2:30am3:30am, 5:00am7:45pm,9:00pm
这是我尝试使用的字符串拆分字符串
List<String> interviewTimingToFrom1 = Arrays.asList(interviewTime1.split(","));
但这不起作用,我只想在列表中拆分 12:00am、3:30am、7:45pm 和列表中的 2:30am、5:00am、9:00am 如何做到这一点,请有人帮忙
您可以使用此正则表达式:
List<String> interviewTimingToFrom1 = Arrays.asList(
interviewTime1.split("\\s*,\\s*|(?<=[ap]m)(?=\\d)"));
正则表达式分解
拆分使用:
\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.