我試圖使用與與string.replace正則表達式替換URL使用正則表達式的網址和代碼如下查找和替換在java中
public class Test {
public static void main(String[] args) {
String test = "https://google.com";
//String regex = "\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
String regex = "(http?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"; // does not match <http://google.com>
String newText = test.replace(regex, "");
System.out.println(newText);
}
}
我已經看着它幾個問題的SO,但它確實不能取代模式。有人可以告訴我,我怎麼做到這一點?
您正則表達式匹配http://google.com,請確保你改變' http?'到'https?' –
我沒有看到任何替換EMENT。你只是想刪除http://google.com? –
@Pedro:非常抱歉。我被趕上了工作,所以這就是爲什麼。非常感謝你的幫助。下次不會再重複這個 –