-1

I need a way to find a span tag inside an HTML and replace the value between the span tag, by using regex. But it should only replace if the span tag contains a specific attribute For example

<span a="hello">a</span><span>b</span> needs to become <span a="hello">c</span><span>b</span>

Is this possible to do in regex? Why I need to do this with regex is because this code runs on the server side and don't have access to allot of fancy Javascript functions.

Emil Rowland
  • 538
  • 5
  • 25

1 Answers1

0

Found a regex solution that worked for me. Know that this is not the best solution but it's the easiest solution on my environment (Adobe Campaign).

html.replace(/(<span[\s\S]*a="hello"[\s\S]*?>)([\s\S]*?)(<\/span>)/g, "$1" + "c" + "$3")
Emil Rowland
  • 538
  • 5
  • 25