jeudi 12 mars 2015

Reg. exp: substring AND whole string

I'm working in VBscript. I have this string:



hello
<!-- @@include file="filename" try="folder1" default="folder2" -->
world


I want to extract "file", the filename, "try", the folder, "default", the other folder, AND I want to get the whole string, from < ! -- to -- > .


This regular expression gets me three matches:



(try|default|file)(="([^"]+)")


The try, default, and file pieces, with submatches in each for the individual segments. That's great, but no matter what I add to the above expression to try and get the entire string as well, e.g.



(!-- @@include (try|default|file)(="([^"]+)") -->)


I go from three matches to just one, losing the try/file/default pieces. There might be more than one @@include, so I need the whole match plus the submatches so I make sure to replace the right tag with the right content.


I can't figure how to alter the expression, help!


Aucun commentaire:

Enregistrer un commentaire