lundi 30 janvier 2023

Regex php - Match some escape characters inside attribute values

Well, basically I'm triying to match some escape characters inside some attributes ("name" & "author").

I'm working on a file uploader where one of the files which is uploaded is a .xml file.

Before parsing it to an XML Format, I'm trying to replace those characters with right format. IE: < to &lt; or ' to &apos; ...etc

These characters are inside single ' quotes or double quotes "

The format of the raw data is:

<info name="Name containing ' apostrophe" author="Lower than < Character" ></info>
<info name='Name containing ' apostrophe' author='Lower than < Character' ></info>

The patter I have just tried is the following one

(name|author)="(\\\\[\\\\"]|[^\\\\"])*"[<|']

However it stopped matching content inside tags.

Aucun commentaire:

Enregistrer un commentaire