regex - excel VB regexp 5.5 capturing group -
i have problem using regexp in excel macro, calling regex.execute(string), instead of getting array of returned capturing groups, single return whole string specified in pattern. using same pattern in http://www.regexr.com/, can see return nicely grouped. missing this:
private sub parsefilename(strinput string) dim regex new regexp dim strpattern string dim strreplace 'sample string \\work_dir\ftp\results\reva\ftp_01_01_06_results\4f\acc2x2r33371_sasssd_run1 strpattern = "ftp_(\w+)_results\\(\w+)\\([\d,\d]+)_(sas|sata)(hdd|ssd)_run(\d)" regex .global = true .multiline = false .ignorecase = false .pattern = strpattern end if regex.test(strinput) set strreplace = regex.execute(strinput) activecell.offset(0, 1) = strreplace.count else activecell.offset(0, 1) = "(not matched)" end if end sub
in end, strreplace.count
shows 1, whole string ftp_01_01_06_results\4f\acc2x8r133371_sasssd_run1
use .submatches
capturing groups values:
private sub parsefilename(strinput string) dim regex new regexp dim strpattern string dim strreplace matchcollection dim long 'sample string \\work_dir\ftp\results\reva\ftp_01_01_06_results\4f\acc2x2r33371_sasssd_run1 strpattern = "ftp_(\w+)_results\\(\w+)\\([\d,\d]+)_(sas|sata)(hdd|ssd)_run(\d)" regex .global = true .multiline = false .ignorecase = false .pattern = strpattern end if regex.test(strinput) set strreplace = regex.execute(strinput) activecell.offset(0, 1) = strreplace.count = 0 5 activecell.offset(i + 1, 1) = strreplace(0).submatches(i) next else activecell.offset(0, 1) = "(not matched)" end if end sub
Comments
Post a Comment