VBScript - RegEx - modify ObjMatch - Pattern = "(\d{2}) (\d{2}) (\d{2})" -
this stumbled across while trying learn little reg ex.
set objregex = createobject("vbscript.regexp") dim re, targetstring, colmatch, objmatch set re = new regexp re .pattern = "(\d{2}) (\d{2}) (\d{2}) 0500z" .global = true .ignorecase = true end targetstring = "02 04 14 0500z joe eating sandwich" set colmatch = re.execute(targetstring) each objmatch in colmatch wscript.echo objmatch date1 = objregex.replace(objmatch, "(\d{2})(\d{2})(\d{2})") wscript.echo date1
issue: need find date shows "02 04 14 0500z" , assign variable in form "020414".
when try replace obj match , reformat date doesn't work, instead showing exact text in brackets.
i referenced: http://www.mikesdotnetting.com/article/24/regular-expressions-and-vbscript http://wiki.mcneel.com/developer/scriptsamples/regexpobject
to refer content captured capturing group, use $n
in replacement string (where n number):
date1 = re.replace(objmatch, "$1$2$3")
to identify number of capturing group, count number of opening parentheses (
belongs capturing group capturing group want refer to:
(\d{2}) (\d{2}) (\d{2}) 0500z ^ ^ ^ 1 2 3
a more complicated example:
((a(?:k)*)(b(c)(?:d)*)) ^^ ^ ^ 12 3 4
(?:pattern)
non-capturing group, doesn't count.
Comments
Post a Comment