%EC%97%90%EC%84%9C%20%EC%A4%91%EB%B3%B5%EB%90%9C%20%ED%81%B0%EB%94%B0%EC%98%B4%ED%91%9C(%EC%95%84%ED%8F%AC%EC%8A%A4%ED%8A%B8%EB%A1%9C%ED%94%BC)%20%EC%82%AD%EC%A0%9C.png)
나는 (문자열에서) 다음 HTML 태그를 가지고 있습니다 :
<meta name="description" content="I love my mother" but I love my sister" more than I can say"/>
보시다시피, 여기에는 4개의 큰따옴표(아포스트로피)가 있습니다.콘텐츠부분. 큰따옴표는 2개만 사용해야 합니다. 하나는 시작 부분에 content="
, 다른 하나는 끝 부분에 있어야 합니다."/>
콘텐츠 섹션에서 2개를 제외하고 다른 큰따옴표가 포함된 모든 태그를 찾아 삭제해야 합니다.
출력은 다음과 같아야 합니다:
<meta name="description" content="I love my mother but I love my sister more than I can say"/>
Regex를 만들었지만 그다지 좋지는 않습니다. 어쩌면 당신이 나를 도울 수 있습니다:
찾다:(?-s)(<meta name="description" content=")(*?\K.*"(?s))"/>
교체:\1\2
답변1
방법은 다음과 같습니다.
- Ctrl+H
- 무엇을 찾다:
(?:<meta name="description" content="|\G(?!^))[^"]*\K"(?=.*?"/>)
- 다음으로 교체:
LEAVE EMPTY
- 확인하다 줄 바꿈
- 확인하다 정규식
- 선택 취소
. matches newline
- Replace all
설명:
(?: # non capture group
<meta name="description" content=" # literally
| # OR
\G(?!^) # restart from last match position (not at the beginning of a line)
) # end group
[^"]* # 0 or more non quote
\K # forget all we have seen until this position
" # a double quote
(?=.*?"/>) # positive lookahead, make sure we have "/> somewhere after
스크린샷(이전):
스크린샷(이후):