2017-01-02 2 views
0

Im Folgenden finden Sie ein String-Variable und mein regulärer Ausdruck, es teilweise funktioniert, aber es ist das Löschen alles nach, und ich möchte nur, dass zum Beispiel eine Eigenschaft entfernen ...Verwirrung mit RegEx

tString='#a5af3c17e39f06875fbe9153d2d66d552{animation-delay: 0s; animation-direction: normal; animation-duration: 0s; animation-fill-mode: none; animation-iteration-count: 1; animation-name: none; animation-play-state: running; animation-timing-function: ease; background-attachment: scroll; background-blend-mode: normal; background-clip: border-box; background-color: rgba(0, 0, 0, 0.498039); background-image: none; background-origin: padding-box; background-position: 0% 0%; background-repeat: repeat; background-size: auto; border-bottom-color: rgb(39, 48, 57); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-bottom-style: none; border-bottom-width: 0px; border-collapse: separate; border-image-outset: 0px; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(39, 48, 57); border-left-style: none; border-left-width: 0px; border-right-color: rgb(39, 48, 57); border-right-style: none; border-right-width: 0px; border-top-color: rgb(39, 48, 57); border-top-left-radius: 0px; border-top-right-radius: 0px; border-top-style: none; border-top-width: 0px; bottom: 0px; box-shadow: rgba(0, 0, 0, 0.4) 0px 2px 20px 0px; box-sizing: border-box; break-after: auto; break-before: auto; break-inside: auto; caption-side: top; clear: none; clip: auto; color: rgb(39, 48, 57); content: ; cursor: auto; direction: ltr; display: block; empty-cells: show; float: none; font-family: Roboto, sans-serif; font-kerning: auto; font-size: 18px; font-stretch: normal; font-style: normal; font-variant: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: normal; font-weight: normal; height: 1110px; image-rendering: auto; isolation: auto; left: 0px; letter-spacing: normal; line-height: 32.4px; list-style-image: none; list-style-position: outside; list-style-type: disc; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; mix-blend-mode: normal; object-fit: fill; object-position: 50% 50%; offset-distance: 0px; offset-path: none; offset-rotation: auto 0deg; opacity: 1; orphans: 2;}' 
 

 
regStr=/animation-direction:.* ;/gm 
 

 
result=tString.replace(regStr,'') 
 

 
console.log(result);

+3

Sie benötigen nicht-gierige Regex dh '. *?' – Fallenhero

+0

Ihre Regex passt alles beginnend mit 'Animation-Richtung:' aber die '. *' bedeutet ** alles * * nach dieser Übereinstimmung ist enthalten (bis zum Ende der Zeichenfolge). Sie können wahrscheinlich eine Übereinstimmung für alles * außer * dem ';' - Zeichen treffen, um sicherzustellen, dass es die Auswahl am Ende der CSS-Regel beendet. – ceejayoz

+2

Siehe https://regex101.com/r/OnTJmx/1 –

Antwort

2

Der .* Teil Ihrer Regexp wählt alles aus. [^;]*; wie in "[nicht;] *;" sollte es tun, je nach Sprache könnte es [!;]*;