Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.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_Arrays - Fatal编程技术网

java中的正则表达式协助

java中的正则表达式协助,java,regex,arrays,Java,Regex,Arrays,我试图提取这些标签中的信息 你好=巴里0238293

我试图提取这些标签中的信息

  • 你好=巴里0238293<

  • hello=terry2938298我认为这应该很接近:
    /hello\=(\w*)\这很有效:

    Pattern p = Pattern.compile("hello=(.*)<");
    Matcher m = p.matcher("hello=bruce8392382<");
    if (m.matches) {
        System.out.println(m.group(1));
    }
    
    Pattern p=Pattern.compile(“hello=(.*)(.*)<)实际上不是一个好的正则表达式。星形限定符是贪婪的,它将消耗所有输入,但是正则表达式引擎会注意到后面有东西,它将开始回溯,直到找到以下文本(本例中的小于号)。这可能会导致严重的性能问题。例如,我在一些代码中有一个这样的问题(我是个懒惰的程序员!),在一个非常小的输入字符串上执行大约需要1100多毫秒


    更好的表达式应该是这样的:
    “hello=”([^这个正则表达式看起来很合理。它是如何工作的?在什么输入上?您可以显示使用该模式的代码吗?…例如:应该是
    “hello=(\\w*))
    
    Pattern p = Pattern.compile("hello=(.*)<");
    Matcher m = p.matcher("hello=bruce8392382<");
    if (m.matches) {
        System.out.println(m.group(1));
    }
    
    ;; create a pattern object
    user=> (def p (java.util.regex.Pattern/compile "hello=([^<]*)<"))
    #'user/p
    
    ;; create a matcher for the string
    user=> (def m (.matcher p "hello=bruce8392382<"))
    #'user/m
    
    ;; call m.matches()
    user=> (.matches m)
    true
    
    ;; call m.group(1) 
    user=> (.group m 1)
    "bruce8392382"