.png)
이 시나리오가 있습니다.
data-cycle-center-horz=true other words
data-cycle-caption=".custom-captions" other words
data-cycle-caption-template="{{slideNum}} other words
before words .data-cycle-caption-template="{{slideNum}} other words
.data-cycle-caption-template="{{slideNum}} other words
그래서 기호로 구분된 모든 단어를 찾아야 합니다.- = . "{
다른 단어 없이 앞뒤에 기호가 있는 단어(전체 문자열)를 검색하고 삭제하기 위해 NOTEPAD++에 대한 정규식을 만들었지만 그다지 좋지는 않습니다.
찾다: (?!\w+[-."={])
REPLACE: (비워두기)
예상되는 결과는 다음과 같습니다.
other words
other words
other words
before words other words
other words
답변1
- Ctrl+H
- 무엇을 찾다:
(?:^|[+=."{}-]+)(?:\w+[+=."{}-]+)+\h*
- 다음으로 교체:
LEAVE EMPTY
- 둘러보기 확인
- 정규식 확인
- Replace all
설명:
(?: # start non capture group
^ # beginning of line
| # OR
[+=."{}-]+ # 1 or more + = . " { } -
) # end group
(?: # start non capture group
\w+ # 1 or more word character
[+=."{}-]+ # 1 or more + = . " { } -
)+ # end group, may appear 1 or more times
\h* # 0 or more horizontal spaces
화면 캡처:
답변2
이것은 Python으로 작성되었으며, 동일한 디렉토리에 있는 "data.txt" 파일에서 테스트 데이터를 로드합니다.
import os, re
path = "./data.txt"
if os.path.isfile(path): #use local leader file
oFile = open(path)
strFile = oFile.read() #get old leaders
oFile.close()
else:
print("File Not Found")
def replace(line):
for i in line:
if ( i == '-' or i == '=' or i == '.' or i == '"' or i == '{' or i == '}'):
line = line.replace(i,"\n")#Delete \n and replace it with xyz to see
return line
lines = strFile.split("\n")
for line in lines:
answer = replace(line)
print(answer)
데이터 사이클 센터 horz true 데이터 사이클 캡션 사용자 정의 캡션 데이터 사이클 캡션 템플릿 SlideNum
답변3
귀하의 질문에서 내가 읽은 것은 기본적으로 모든 단어를 일치시키고 싶지만 구분하는 특수 문자는 일치시키지 않는다는 것입니다. 그렇죠?
[^-=."{}\r\n]+
트릭을 수행해야합니다. 특수 - = . "{
문자나 줄 바꿈이 아닌 모든 항목과 일치합니다 .
다음과 같은 온라인 도구를 사용하여 정규식을 작성하고 테스트할 수 있습니다.정규식101
업데이트
다음 정규식은 설명된 단어와 후행 공백을 제거합니다.([^\s]+[-=."{}\r\n][^\s]+\s*)+
귀하의 예에서 성공적으로 테스트했습니다.
전에:
data-cycle-center-horz=true other words
data-cycle-caption=".custom-captions" other words
data-cycle-caption-template="{{slideNum}} other words
before words .data-cycle-caption-template="{{slideNum}} other words
.data-cycle-caption-template="{{slideNum}} other words
후에:
other words
other words
other words
before words other words
other words