代码之家  ›  专栏  ›  技术社区  ›  Vinayak Bevinakatti

正则表达式(Java)

  •  0
  • Vinayak Bevinakatti  · 技术社区  · 17 年前

    如何匹配以下字符串?

    http://localhost:8080/MenuTest/index.action
    

    如果上面的模式中包含“menutest”,则regex应返回true。

    干杯

    4 回复  |  直到 17 年前
        1
  •  9
  •   Peter Boughton    17 年前

    也许你不需要雷吉士?

    String url = "http://localhost:8080/MenuTest/index.action";    
    boolean hasWhatImLookingFor = url.contains("MenuTest");
    
        2
  •  1
  •   Peter Boughton    17 年前

    如果需要检查是否出现“menutest” 在那个特定的位置 (即主机/端口之后),则可以使用:

    ^https?://[^/]++/MenuTest
        3
  •  0
  •   miccet    17 年前

    沿着这条线?(未经测试)

    Regex r = new Regex("MenuTest");
    r.search("http://localhost:8080/MenuTest/index.action");
    System.out.println(""+r.didMatch());
    
        4
  •  0
  •   Andrew Swan    17 年前

    你寻找的正则表达式只是“menutest”,没有引号。除非问题比看起来更复杂?