我想從String
中刪除字符序列,如"htsap://"
或"ftsap://"
。可能嗎?
讓我用一個例子來說明我的需求。刪除與正則表達式匹配的所有單詞
實際輸入字符串:
"Every Web page has a http unique address called a URL (Uniform Resource Locator) which identifies where it is located on the Web. For "ftsap://"example, the URL for CSM Library's home page is: "htsap://"www.smccd.edu/accounts/csmlibrary/index.htm The basic parts of a URL often provide \"clues\" to htsap://where a web page originates and who might be responsible for the information at that page or site."
預期的結果String:
"Every Web page has a http unique address called a URL (Uniform Resource Locator) which identifies where it is located on the Web. For example, the URL for CSM Library's home page is: www.smccd.edu/accounts/csmlibrary/index.htm The basic parts of a URL often provide \"clues\" to where a web page originates and who might be responsible for the information at that page or site."
模式我想:(還不是很確定這是一個正確的方式)
((.*?)(?=("htsap://|ftsap://")))
和:
((.*?)(?=("htsap://|ftsap://")))(.*)
任何人都可以在這裏建議嗎?
正確,如果我錯了,但'g'lobal標誌應該用於'replaceAll'或等效方法未被使用。 –
你是對的!其實,我在我的例子中使用了這個標誌(在我的答案中,永久鏈接** regex101 **)。 – ccjmne
好吧,我現在看到。感謝澄清。 –