Hi everyone,

got in a bit of a mess trying to use regex. I had a look in the forums and picked up bits that I might need but could not quite figure out how it works.

I am trying to split a line of delimited data using the split function which works fine until for example I come accros something like this

"Hello","World","Hello,World" which when using "," as the delimiter gives me 4 elements in my array rather than 3. I know I could use (",") this as my delimiter but would this be the most efficient way of doing this?

Oh, I nearly forgot AND I get an error (run-time error 5017) when I try and do my replace.

Thanks your your help

Gogi

VB Code:
  1. Private Sub Command1_Click()
  2.  
  3. Dim mainFile As Integer
  4. Dim text As String
  5. Dm regEx As New RegExp 'Regular Expression object
  6. Dm str1 As String
  7. Dim strReplace As String
  8. Dim Delimiter As String
  9.  
  10. mainFile = FreeFile
  11.  
  12. Open "C:\test data\test.txt" For Binary As mainFile
  13.  
  14. Seek mainFile, 1
  15.  
  16. Line Input #mainFile, text
  17.  
  18. Delimiter = ","
  19.  
  20. regEx.Pattern = "(?<="")[^" & Delimiter & "].*?[^" & Delimiter & "](?="")"
  21.  
  22. str1 = text
  23.  
  24. strReplace = "~"
  25.  
  26. Debug.Print str1
  27.  
  28. str1 = regEx.Replace(str1, strReplace)
  29.  
  30. Debug.Print str1
  31.  
  32. end sub