내가 좋아하는 캐릭터 시퀀스를 제거 할 것인지 "htsap://"
또는 "ftsap://"
A로부터 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 "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."
예상되는 결과 문자열 :
"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://")))(.*)
누구든지 여기에 제안 해 주시겠습니까?
샘플 내에서 인용문을 이스케이프하므로 String
Java로 작업한다고 가정합니다.
다음을 시도해야합니다.
final String res = input.replaceAll("\"?\\w+://\"?", "");
다음은 이 정규식이 정확히 일치하는 작업 예제에 대한 링크입니다 !
작동 원리 :
일련의 영숫자 (및 밑줄),이 (가) 뒤 따르 ://
거나 앞뒤로 올 수있는 경우 일치하고 제거합니다 "
.
편집 : 사용하여 동일한 결과를 얻는 방법 Matcher
?
final String input = "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.";
final Pattern p = Pattern.compile("\"?\\w+://\"?");
final StringBuilder b = new StringBuilder(input);
Matcher m;
while((m = p.matcher(b.toString())).find()) {
b.replace(m.start(), m.end(), "");
}
System.out.println(b.toString());
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다