Description |
Given that you have a string that is comprised characters/words separated by spaces and you want to creates matches of those words/characters but you also have substring groups of words/characters/spaces enclosed in [] and "" that you want treated as a single match, this pattern is what worked for me. Feel free to modify this regex to fit your needs if your string groups are not grouped by [] or "". Please let me know if this doesn't test well for you. ********** Example Test String:
212.183.143.4 - - [03/May/2007:21:03:27 +0100] "GET mp4-amrnb.3gp RTSP/1.0" 200 155527 [RealOnePlayer_s60.26.25.01_21-Jun-2005_13:02:43_epoc_av21_thumb] [3e546ed1-f9b1-11db-eb72-1d98b80ca9f5] [UNKNOWN] 454492 102 47 0 0 [0 0 0 0] [03/May/2007:21:02:38] 192.168.0.2 24245 55 ********** Matches:
Matches(0) = "212.183.143.4"
Matches(1) = "-"
Matches(2) = "-"
Matches(3) = "[03/May/2007:21:03:27 +0100]"
Matches(4) = ""GET mp4-amrnb.3gp RTSP/1.0""
Matches(5) = "200"
Matches(6) = "155527"
Matches(7) = "[RealOnePlayer_s60.26.25.01_21-Jun-2005_13:02:43_epoc_av21_thumb]"
Matches(8) = "[3e546ed1-f9b1-11db-eb72-1d98b80ca9f5]"
Matches(9) = "[UNKNOWN]"
Matches(10) = "454492"
Matches(11) = "102"
Matches(12) = "47"
Matches(13) = "0"
Matches(14) = "0"
Matches(15) = "[0 0 0 0]"
Matches(16) = "[03/May/2007:21:02:38]"
Matches(17) = "192.168.0.2"
Matches(18) = "24245"
Matches(19) = "55"
********** ASP Test Code:
Set regEx = New RegExp
regEx.Global = True
regEx.IgnoreCase = True
regEx.MultiLine = True
teststring = "<<your string>>"
regEx.Pattern = "\S*?[\[|\""].*?[\]|\""]|\S+"
Set Matches = regEx.Execute(teststring) |