如何在 Java Regex 中匹配不包含某個單詞的行


範例

互動範例

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NoRegTest {
   public static void main(String[] args) {
      String s="^fun";
      Pattern pattern = Pattern.compile(s);
      Matcher matcher = pattern.matcher("Java is fun");

      if(!matcher.find()) {
         System.out.println("not found");
      }
   }
}

輸出

not found

更新於: 2020-06-21

317 瀏覽量

開啟你的 職業生涯

透過完成課程獲得認證

開始入門
廣告