Splitting without getting delimiters in array

G

Guest

Hi!

I use a regex (?<!\\?)('|\\+|:) to split a string to a String[].

The String[] i get after splitting is correctly splitted but contains all
the delimiters i use to decide where the string should be splitted.

Do I have to loop through the array and find every index containing a single
delimiter or is there a easier way to do this.

Regards / gustav
 
K

Kevin Spencer

According to the documentation, if you employ capturing groups in the
Regular Expression (which you did), it will include the groups in the array.
Try this instead:

(?<!\?)['+:]

It uses a character class to determine the delimiter characters, without
grouping.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top