如何根据多个分隔符拆分()一个字符串?
How to split() a string with respect to multiple delimiters?
正在尝试提取文本 18-Aug-2019 14:00 形式 Egypt Today 最后更新时间:18-Aug-2019 14:00 (GMT) 并且我的步骤是在“:”处拆分作为第一步,然后进行拆分“(”部分(基本上是 2 个拆分),而 2 个拆分不起作用...我们可以做这仅需一步?谢谢
代码试验:
lastupdated1=lastupdated.split("Last Update Time: ")[1]
lastupdated2=lastupdated1.split(" (GMT")[0]
错误是:
2019-08-19 14:54:53.692 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/REGIONAL MARKET NEWS/Verify_whether_news_getting_updated FAILED.
Reason:
java.util.regex.PatternSyntaxException: Unclosed group near index 5
(GMT
at java_lang_String$split[=11=].call(Unknown Source)
at Verify_whether_news_getting_updated.run(Verify_whether_news_getting_updated:41)
您可以轻松提取文本 18-Aug-2019 14:00 表格 Egypt Today 最后更新时间:18-Aug-2019 14:00 (GMT) using split()
only once passing a regex and you can use the following solution:
代码块:
String myNewString = "Egypt Today Last Update Time: 18-Aug-2019 14:00 (GMT)";
String[] tokens = myNewString.split(": |\(");
System.out.println(tokens[1]);
控制台输出:
18-Aug-2019 14:00
正在尝试提取文本 18-Aug-2019 14:00 形式 Egypt Today 最后更新时间:18-Aug-2019 14:00 (GMT) 并且我的步骤是在“:”处拆分作为第一步,然后进行拆分“(”部分(基本上是 2 个拆分),而 2 个拆分不起作用...我们可以做这仅需一步?谢谢
代码试验:
lastupdated1=lastupdated.split("Last Update Time: ")[1]
lastupdated2=lastupdated1.split(" (GMT")[0]
错误是:
2019-08-19 14:54:53.692 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/REGIONAL MARKET NEWS/Verify_whether_news_getting_updated FAILED.
Reason:
java.util.regex.PatternSyntaxException: Unclosed group near index 5
(GMT
at java_lang_String$split[=11=].call(Unknown Source)
at Verify_whether_news_getting_updated.run(Verify_whether_news_getting_updated:41)
您可以轻松提取文本 18-Aug-2019 14:00 表格 Egypt Today 最后更新时间:18-Aug-2019 14:00 (GMT) using split()
only once passing a regex and you can use the following solution:
代码块:
String myNewString = "Egypt Today Last Update Time: 18-Aug-2019 14:00 (GMT)"; String[] tokens = myNewString.split(": |\("); System.out.println(tokens[1]);
控制台输出:
18-Aug-2019 14:00