[英]Regular Expression Matching Java
我正在處理正則表達式匹配問題。 問題是,我想將一個字符串與7個以上的字符串匹配(任何字符,包括數字,字母,特殊字符)。 我正在使用以下表達式(我刪除了開頭和結尾符號),但沒有按照我的想法工作。 有什么想法嗎?
"((\\w|W){7,})"
Java代碼:
final String VALID_REGEX =
"^((\\w{2,6})" // 2 to 6 characters
+ "(?:[\\r\\n]{1,3})" // 1 or 3 carriage returns
+ "([\\w\\W]{7,})" // equal to or more than 7 characters or spaces
+ "(?:[\\r\\n]{1,3})" // 1 or 3 carriage returns
+ "(?:[\\w\\W])*"; // Any text
Pattern regExPattern = Pattern.compile(VALID_REGEX, Pattern.DOTALL);
String content = new String(Files.readAllBytes(Paths.get("/home/hqu/Downloads/test.txt")));
Matcher noMatcher = regExPattern.matcher(content);
if(noMatcher.matches())
System.out.println("match");
else
System.out.println("not match");
輸入:
不太確定,請更換
“([[\\ w \\ W] {7,})”
與
“([[\\ w |] {7,})”
適用於我的測試用例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.