繁体   English   中英

LucidWorks:Java正则表达式和GNU正则表达式

[英]LucidWorks: Java Regular Expressions & GNU Regular Expressions

我正在尝试创建正则表达式,以便可以使用LucidWorks对我的网站上的某些URL进行爬网和索引。

范例网址: http : //www.example.com/reviews/assassins-creed-revelations/24475 / reviews /范例网址: http : //www.example.com/reviews/super-mario-3d-land/64303 /评论/

基本上,我希望LucidWorks搜索我的整个网站,并且仅索引URL末尾带有/ reviews /的URL。

谁能帮我构建一个表达式来做到这一点? :)

更新:

网址: http//www.example.com/

包含路径: / / * /评论/ *

这种工作方式有效,但只会抓取第一页,而不会进入具有更多评论(1、2、3等)的下一页。

如果我还添加: // //reviews/.*

我得到了一些我不想索引的页面,例如http://www.example.com/?page=2

Check with this function
public boolean canAcceptURL(String url,String endsWith){
    boolean canAccept = false;
    String regex = "";
    try{
        if(endsWith.equals("")){
            endsWith = "/reviews/";
        }
    regex = "[\\x20-\\x7E]*"+endsWith+"$";//Check the url string u passed ends     with the endString you hav passed.If end string is null it will take the default value.
        canAccept = url.matches(regex);
    }catch (PatternSyntaxException pe) {
        pe.printStackTrace();
    }catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("String matches : "+canAccept);
    return canAccept;
}

Sample out put :
calling function : canAcceptURL("http://www.example.com/reviews/super-mario-3d-land/64303/reviews/","/reviews/");
String matches : true

if you want to get the url contains *'/reviews/'* just change the regex string to

String regex = "[\\x20-\\x7E]*/reviews/[\\x20-\\x7E]*"; // this will accept a string with white space and special character.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM