regex - Vbscript Regular expression, find all between 2 known strings -
i select texts between 2 know strings. example following text
*starthere *general settings * text1 * text2 *endhere i select texts between "*starthere" , "*endhere" using vbscript. final output looks following
*general settings * text1 * text2 i know simpler using regex since there multiple instances of such pattern in file read.
i tried following
/(.*starthere\s+)(.*)(\s+*endhere.*)/ /(*starthere)(?:[^])*?(*endhere)/ but dont seem work , selects start , end strings together. lookforward , backword dont seem work either , iam not sure if have support vbscript.
this code using:
'create regular expression object dim objregexp set objregexp = new regexp 'set our pattern objregexp.pattern = "/\*starthere\s+([\s\s]*?)\s+\*endhere\b/" objregexp.ignorecase = true objregexp.global = true until objfile.atendofstream strsearchstring = objfile.readline dim objmatches set objmatches = objregexp.execute(strsearchstring) if objmatches.count > 0 out = out & objmatches(0) &vbcrlf wscript.echo "found" end if loop wscript.echo out objfile.close
you can use:
/\bstarthere\s+([\s\s]*?)\s+endhere\b/ and grab captured group #1
([\s\s]*?) match text between these 2 tags including newlines.
Comments
Post a Comment