dimanche 19 avril 2015

vbs reg ex extract block within text

I want to extract each "blocks" of sub text using regex. My reg ex expression gets the correct start but also returns everything to the end of my file.


I am using:


re.ignorecase = true


re.multiline = false


re.global = true


re.pattern = "\balias\s=\sX[\s\S]{1,}end"


An example of the file format is:


Metadata Begin



Easting Begin

alias = X

projection = "geodetic"

datum = "GDA94"

Easting End

Northing Begin

alias = Y

projection = "geodetic"

datum = "GDA94"

Northing End


Metadata End


I want to extract the text starting at alias up to the next End for each occurrence so I can deal with the details one alias at a time. e.g. alias = X projection = "geodetic" datum = "GDA94" Easting End


But this does not get the first End after the alias. Instead the [\s\S] is matching everything after that first alias upto the end of the file. But [\s\S] is the only trick I can think of get past the CrLf at the end of each line. Is there a regex that match upto the first End over multiple lines? Thank you.


Aucun commentaire:

Enregistrer un commentaire