0

I am attempting to remove the <span class="notranslate"></span> of a string using a regex. Basically it's because Google Translate API needs that kind of wrapping if some string should not be translated, which is what I need.

I have that regex to do this (it needs to handle new lines, that's why [\S\s] is used instead of .) :

<span class="notranslate">[\S\s]+(?=<\/span>)<\/span>

However when testing it, it is way too greedy because for that input for example:

<span class="notranslate">%1</span> per il seguente motivo: <span class="notranslate">\n</span> <span class="notranslate">%2!d!</span>

That regex gets the whole string. I was a little confused because many answers (including "How to match "anything up until this sequence of characters" in a regular expression?") seems to indicate that ? as a non greedy thing.

I need to have it find every span wrap with the notranslate class, not all of them if there are many.

Micaël Félix
  • 2,697
  • 5
  • 34
  • 46

0 Answers0