in reply to Re: Regex for escaping spaces in strings when there are quotes
in thread Regex for escaping spaces in strings when there are quotes
For anyone that's interested, here's the new JavaScript code:
No extra arrays needed, and the function is basically a one liner... The VB implementation is just as simple, a single Regex, but of course, we have to iterate through the Matches collection and stored each value into an array for the return value. If anyone wants to see how ugly Regexes are in VBScript, here you are:<SCRIPT LANGUAGE="JavaScript"> function ParseStringRegExp (strSource) { // Split the modified string by spaces or quoted strings. var aryOutput = strSource.match (/"[^"]*"|\S+/g); return (aryOutput); } </SCRIPT>
<% Function ParseStringRegExp (strSource) Dim objRegex Dim colMatches Dim objMatch Set objRegex = New RegExp ' Create a regular expression +object. objRegex.Pattern = """[^""]*""|\S+" ' Set pattern. objRegex.Global = True ' Set global applicabi +lity. Set colMatches = objRegex.Execute(strSource) ' Execute search. Dim aryOutput() ReDim aryOutput(colMatches.Count - 1) ' Prepare the output a +rray. Dim lngMatchCounter ' Grab the colMatches collection and store each value into an array. lngMatchCounter = 0 For Each objMatch In colMatches aryOutput(lngMatchCounter) = objMatch.Value lngMatchCounter = lngMatchCounter + 1 Next ParseStringRegExp = aryOutput End Function %>
|
|---|