views:

32

answers:

2

Hi,

I would like to split a string into an array according to a regular expression similar to what can be done with preg_split in PHP or VBScript Split function but with a regex in place of delimiter.

Using VBScript Regexp object, I can execute a regex but it returns the matches (so I get a collection of my splitters... that's not what I want)

Is there a way to do so ?

Thank you

A: 

You can alway use the returned array of matches as input to the split function. You split the original string using the first match - the first part of the string is the first split, then split the remainder of the string (minus the first part and the first match)... continue until done.

Oded
+1  A: 

If you can reserve a special delimiter string, i.e. a string that you can choose that will never be a part of the real input string (perhaps something like "#@#"), then you can use regex replacement to replace all matches of your pattern to "#@#", and then split on "#@#".

Another possibility is to use a capturing group. If your delimiter regex is, say, \d+, then you search for (.*?)\d+, and then extract what the group captured in each match (see before and after on rubular.com).

polygenelubricants