Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何根据多个分隔符拆分()字符串?_Java_Regex_String_Selenium_Katalon Studio - Fatal编程技术网

Java 如何根据多个分隔符拆分()字符串?

Java 如何根据多个分隔符拆分()字符串?,java,regex,string,selenium,katalon-studio,Java,Regex,String,Selenium,Katalon Studio,试图提取文本2019年8月18日14:00表单埃及今日最后更新时间:2019年8月18日14:00(GMT),我的步骤是在“:“作为第一步,然后进行拆分”(“部分(基本上是两次拆分),两次拆分不起作用…我们可以只从一个步骤执行此操作吗?谢谢 代码试用: lastupdated1=lastupdated.split("Last Update Time: ")[1] lastupdated2=lastupdated1.split(" (GMT")[0] 错误是: 2019-08-19 14:54:

试图提取文本2019年8月18日14:00表单埃及今日最后更新时间:2019年8月18日14:00(GMT),我的步骤是在“:“作为第一步,然后进行拆分”(“部分(基本上是两次拆分),两次拆分不起作用…我们可以只从一个步骤执行此操作吗?谢谢

代码试用:

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$0.call(Unknown Source)
        at Verify_whether_news_getting_updated.run(Verify_whether_news_getting_updated:41)

您可以轻松提取文本2019年8月18日14:00表单埃及今日最后更新时间:2019年8月18日14:00(GMT)使用
split()
仅通过一次a,您可以使用以下解决方案:

  • 代码块:

    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
    

错误消息很清楚。在正则表达式
(GMT
中有一个未关闭的组。即,您已开始使用一些括号,但尚未完成。我假定您希望匹配一个文字开头括号,因此需要对其进行转义。在java中,您需要转义,因此请使用
\\(改为GMT
。非常感谢,现在工作正常。当然,没有问题关键是
。split
需要一个正则表达式。