Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.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 Regex:Find&;串替换_Java_Regex - Fatal编程技术网

Java Regex:Find&;串替换

Java Regex:Find&;串替换,java,regex,Java,Regex,我有一根绳子 String customHtml = "<html><body><iframe src=https://zarabol.rediff.com/widget/end-of-cold-war-salman-hugs-abhishek-bachchan?search=true&header=true id=rediff_zarabol_widget name=rediff_zarabol_widget scrolling=auto transpar

我有一根绳子

String customHtml = "<html><body><iframe src=https://zarabol.rediff.com/widget/end-of-cold-war-salman-hugs-abhishek-bachchan?search=true&header=true id=rediff_zarabol_widget name=rediff_zarabol_widget scrolling=auto transparency= frameborder=0 height=500 width=100%></iframe></body></html>";

我尝试使用Lazy
/begin.*?end/
,但失败了。 我们将非常感谢您的帮助。 提前谢谢

Regex:

(?<=\/)[^\/]*(?=\?)

Java代码应该是

String url= "<html><body><iframe src=https://zarabol.rediff.com/widget/end-of-cold-war-salman-hugs-abhishek-bachchan?search=true&header=true id=rediff_zarabol_widget name=rediff_zarabol_widget scrolling=auto transparency= frameborder=0 height=500 width=100%></iframe></body></html>";
String m1 = url.replaceAll("(?<=\\/)[^\\/]*(?=\\?)", "srk-confesses-found-gauri-to-be-physically-attractive");
System.out.println(m1);
stringurl=”“;
字符串m1=url.replaceAll(“(?Regex:

Java代码应该是

String url= "<html><body><iframe src=https://zarabol.rediff.com/widget/end-of-cold-war-salman-hugs-abhishek-bachchan?search=true&header=true id=rediff_zarabol_widget name=rediff_zarabol_widget scrolling=auto transparency= frameborder=0 height=500 width=100%></iframe></body></html>";
String m1 = url.replaceAll("(?<=\\/)[^\\/]*(?=\\?)", "srk-confesses-found-gauri-to-be-physically-attractive");
System.out.println(m1);
stringurl=”“;
字符串m1=url.replaceAll(“(?Regex:

Java代码应该是

String url= "<html><body><iframe src=https://zarabol.rediff.com/widget/end-of-cold-war-salman-hugs-abhishek-bachchan?search=true&header=true id=rediff_zarabol_widget name=rediff_zarabol_widget scrolling=auto transparency= frameborder=0 height=500 width=100%></iframe></body></html>";
String m1 = url.replaceAll("(?<=\\/)[^\\/]*(?=\\?)", "srk-confesses-found-gauri-to-be-physically-attractive");
System.out.println(m1);
stringurl=”“;
字符串m1=url.replaceAll(“(?Regex:

Java代码应该是

String url= "<html><body><iframe src=https://zarabol.rediff.com/widget/end-of-cold-war-salman-hugs-abhishek-bachchan?search=true&header=true id=rediff_zarabol_widget name=rediff_zarabol_widget scrolling=auto transparency= frameborder=0 height=500 width=100%></iframe></body></html>";
String m1 = url.replaceAll("(?<=\\/)[^\\/]*(?=\\?)", "srk-confesses-found-gauri-to-be-physically-attractive");
System.out.println(m1);
stringurl=”“;
字符串m1=url.replaceAll(“(?Regex:
[^/]*?(?:\?)

必须从正则表达式中删除“/”。

正则表达式: [^/]*?(?:\?)

必须从正则表达式中删除“/”。

正则表达式: [^/]*?(?:\?)

必须从正则表达式中删除“/”。

正则表达式: [^/]*?(?:\?)


您必须从正则表达式中删除“/”。

正如其他人所说,DOM解析器会更好。为了完成此操作,这里有一个正则表达式解决方案,它将适用于您的输入:

String replaced = yourString.replaceAll("(https://\\S+/)[^?]+", 
                    "$1srk-confesses-found-gauri-to-be-physically-attractive");
解释

  • (https://\\S+/)
    将文本
    https://
    、任何非空格的字符
    \S+
    和正斜杠
    /
    捕获到组1中
  • [^?]+
    匹配任何不是
    的字符(要替换的文本)
  • 我们将替换为
    $1
    第1组(未更改)和您指定的文本

正如其他人所说,DOM解析器会更好。作为补充,下面是一个适用于您的输入的正则表达式解决方案:

String replaced = yourString.replaceAll("(https://\\S+/)[^?]+", 
                    "$1srk-confesses-found-gauri-to-be-physically-attractive");
解释

  • (https://\\S+/)
    将文本
    https://
    、任何非空格的字符
    \S+
    和正斜杠
    /
    捕获到组1中
  • [^?]+
    匹配任何不是
    的字符(要替换的文本)
  • 我们将替换为
    $1
    第1组(未更改)和您指定的文本

正如其他人所说,DOM解析器会更好。作为补充,下面是一个适用于您的输入的正则表达式解决方案:

String replaced = yourString.replaceAll("(https://\\S+/)[^?]+", 
                    "$1srk-confesses-found-gauri-to-be-physically-attractive");
解释

  • (https://\\S+/)
    将文本
    https://
    、任何非空格的字符
    \S+
    和正斜杠
    /
    捕获到组1中
  • [^?]+
    匹配任何不是
    的字符(要替换的文本)
  • 我们将替换为
    $1
    第1组(未更改)和您指定的文本

正如其他人所说,DOM解析器会更好。作为补充,下面是一个适用于您的输入的正则表达式解决方案:

String replaced = yourString.replaceAll("(https://\\S+/)[^?]+", 
                    "$1srk-confesses-found-gauri-to-be-physically-attractive");
解释

  • (https://\\S+/)
    将文本
    https://
    、任何非空格的字符
    \S+
    和正斜杠
    /
    捕获到组1中
  • [^?]+
    匹配任何不是
    的字符(要替换的文本)
  • 我们将替换为
    $1
    第1组(未更改)和您指定的文本
    • 这应该可以做到:

      url = url.replaceAll("(?<=/)[^/?]+(?=\\?)", "your new text");
      
      url=url.replaceAll((?这应该可以:

      url = url.replaceAll("(?<=/)[^/?]+(?=\\?)", "your new text");
      
      url=url.replaceAll((?这应该可以:

      url = url.replaceAll("(?<=/)[^/?]+(?=\\?)", "your new text");
      
      url=url.replaceAll((?这应该可以:

      url = url.replaceAll("(?<=/)[^/?]+(?=\\?)", "your new text");
      


      url=url.replaceAll(“(?您肯定需要一个html解析器。不要对html内容使用正则表达式。它会减慢速度。我不认为正则表达式是解析html的正确工具。您可能会从阅读中获益。尝试使用JSoup来解析html,而不是基于正则表达式的匹配。我认为正则表达式是正确的选择,因为html解析器在这种情况下只能解析整个urlcase@Faheem做所有这些标记都在一行上?你肯定需要一个html解析器。不要对html内容使用正则表达式。它会减慢速度。我不认为正则表达式是解析html的正确工具。你可能会从阅读中获得一些东西,尝试使用JSoup解析html而不是基于正则表达式的匹配。我认为正则表达式是正确的选择,因为html解析器只能解析html在这个页面中添加整个urlcase@Faheem所有这些标记都在一行上吗?你肯定需要一个html解析器。不要对html内容使用正则表达式。它会减慢速度。我认为正则表达式不是解析html的正确工具。你可能会从阅读中获得一些东西。试着使用JSoup来解析html而不是基于正则表达式的匹配。我认为正则表达式是正确的选择因为html解析器只能解析此文件中的整个urlcase@Faheem所有这些标记都在一行上吗?你肯定需要一个html解析器。不要对html内容使用正则表达式。它会减慢速度。我不认为正则表达式是解析html的正确工具。你可能会从阅读中获得一些东西。试着使用JSoup来解析html,而不是基于正则表达式的匹配。I我认为正则表达式是正确的选择,因为html解析器在这种情况下只能解析整个urlcase@Faheem所有这些标签都在一行吗?不需要转义正斜杠。不需要转义正斜杠。不需要转义正斜杠。不需要转义正斜杠。不需要转义正斜杠。