user1534881
user1534881

Reputation: 23

allow simple quote and double quote in regex

I've got this regex /src='cid:(.*)'/Uims and it works fine but only match element in single quote . What is the way to also allow result who match double quotes (like /src="cid:(.*)"/Uims) but in a single regex?

Upvotes: 2

Views: 184

Answers (2)

mogelbrod
mogelbrod

Reputation: 2306

/src=(["'])cid:(.*?)\1/Uims

Store the type of quotation as a back reference and refer to it where it should be closed.
Note that the back reference you are using will be located at \2 (or $2) instead of \1.

Oh, and you probably want to make the grouping lazy (non-greedy), so I added a ? after .*. See regular-expressions.info for more info.

Upvotes: 4

igustin
igustin

Reputation: 1118

Try

...'\''...

on each occurrence of single quote.

Upvotes: 0

Related Questions