.png)
Ich habe dieses Szenario:
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
Ich muss also alle Wörter finden, die durch Zeichen getrennt sind- = . "{
Ich habe einen regulären Ausdruck für NOTEPAD++ erstellt, um die Wörter zu suchen und zu löschen, vor und nach denen Zeichen stehen (der gesamte String), ohne die anderen Wörter, aber nicht sehr gut:
SUCHEN: (?!\w+[-."={])
ERSETZEN: (leer lassen)
Das erwartete Ergebnis sollte sein:
other words
other words
other words
before words other words
other words
Antwort1
- Ctrl+H
- Finde was:
(?:^|[+=."{}-]+)(?:\w+[+=."{}-]+)+\h*
- Ersetzen mit:
LEAVE EMPTY
- check Umwickeln
- check Regulärer Ausdruck
- Replace all
Erläuterung:
(?: # 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
Bildschirmaufnahme:
Antwort2
Dies ist in Python geschrieben. Es lädt Ihre Testdaten aus einer Datei „data.txt“ im selben Verzeichnis
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)
Datenzyklus-Center, horizontal, echte Datenzyklus-Beschriftung, benutzerdefinierte Beschriftungen, Datenzyklus-Beschriftungsvorlage, SlideNum
Antwort3
Aus Ihrer Frage entnehme ich, dass Sie grundsätzlich alle Wörter abgleichen möchten, nicht jedoch die trennenden Sonderzeichen, richtig?
[^-=."{}\r\n]+
sollte funktionieren. Es wird alles abgeglichen, was keine Sonderzeichen - = . "{
oder Zeilenumbrüche sind.
Sie können Regex mit einem Online-Tool wie erstellen und testenregex101
Aktualisieren
Der folgende reguläre Ausdruck entfernt die Wörter wie beschrieben sowie nachstehende Leerzeichen:([^\s]+[-=."{}\r\n][^\s]+\s*)+
Ich habe es an deinem Beispiel erfolgreich getestet:
Vor:
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
Nach:
other words
other words
other words
before words other words
other words