smilelife
smilelife

Reputation: 195

Perl substitute ignore everything between brackets

I have a string like: 'Hello "Jay" < img src="hello.png">'

I am extracting the string and escaping double/single quotes using a simple substitute:

$string =~ s/\"/\\\"/g;

The problem is that I dont want to escape those double quotes inside the tag

Is there a way ignore all double quotes between <..>

Upvotes: 0

Views: 222

Answers (2)

samby
samby

Reputation: 1

s/\"(?![^<>]*>)/\\\"/g

\" matches double quotes

(?![^<>]*>) negative lookahead, implies that it will not match anything within [^<>]*

Upvotes: -1

gymbrall
gymbrall

Reputation: 2063

Try this and see if it works for you:

s/\"(?![^<>]*>)/\\\"/g;

If it doesn't give me a longer input string to test with.

Upvotes: 2

Related Questions