Friday, 15 March 2013

regex - excel VB regexp 5.5 capturing group -


"postprint" itemprop = "text">

I'm getting an array of excel macros, using regexp instead of calling a problem regex.execute (string) instead of calling By the group capturing, I always get a single return which is the full string specified in the pattern. Using the same pattern, I can see well-grouped return. What I'm missing from:

  Private Sub ParseFileName (as strInput string) Dim regex New RegExp dim strPattern string retard strReplace 'sample string \\ Work_DIR \ FTP \ result form As in \ Rev. \ FTP_01_01_06_Results \ 4F \ ACC2X2R33371_SASSSD_run1 strPattern = "FTP _ (\ w +) _ \\ (\ w +) \\ ([\ d, \ D]) _ (SAS | SATA) (HDD) | SSD) _run (\ d) "with regex. Globals = true .MultiLine = false .IgnoreCase = false .Pattern = strPattern then ends with regEx.Test (strInput) then set strReplace = regEx.Execute (strInput) ActiveCell. Offset (0, 1) = strReplace.Count or ActiveCell. Offset (0, 1) = "(not matched)" end if ending sub  

Finally, strReplace.Count always displays 1, which is complete String FTP_01_01_06_Results \ 4F \ ACC2X8R133371_SASSSD_run1

use .ubmatches capture groups values To get:

  Personal Sue ParseFileName (as the strInput string) Dim regex New RegExp dim strPattern string retard strReplace as MatchCollection dim as long as I'Sample String \\ Work_DIR \ FTP \ as result \ Revava \ 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 with IgnoreCase = false .Pattern = strPattern end then regEx.Test (strInput) then set strReplace = regEx .Execute (strInput) with ActiveCell.Offset (0, 1) = strReplace.Count for I = 0 to 5 ActiveCell.Offset (i + 1, 1) = strReplace (0) .SubMatches (i) Next or ActiveCell.Offset (0, 1) = "(not matching)" means the last if End Sub  

No comments:

Post a Comment