Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Split VS. Regex.Split?

If I have a delimited text file with a basic delimiter (say | for instance) does it make a difference whether I use a String or a Regex split?

Would I see any performance gains with one versus the other?

I am assuming you would want to use Regex.Split if you have escaped delimiters that you don't want to split on (\| for example).

Are there any other reasons to use Regex.Split vs String.Split?

like image 702
Abe Miessler Avatar asked Aug 30 '10 14:08

Abe Miessler


People also ask

Is regex faster than string split?

split is faster, but complex separators which might involve look ahead, Regex is only option.

Does string split use regex?

split(String regex) method splits this string around matches of the given regular expression. This method works in the same way as invoking the method i.e split(String regex, int limit) with the given expression and a limit argument of zero.

What is regex split?

The RegEx Split processor provides a way to split up the data in an attribute into an array, using a regular expression to define where the splits should occur. Use RegEx Split to split up data where you need a more advanced way of splitting up the data than using delimiters.

Does Python split using regex?

Introduction to the Python regex split() functionpattern is a regular expression whose matches will be used as separators for splitting. string is an input string to split. maxsplit determines at most the splits occur. Generally, if the maxsplit is one, the resulting list will have two elements.


1 Answers

Regex.Split is more capable, but for an arrangement with basic delimitting (using a character that will not exist anywhere else in the string), the String.Split function is much easier to work with.

As far as performance goes, you would have to create a test and try it out. But, don't pre-optimize, unless you know that this function will be the bottleneck for some essential process.

like image 170
John Fisher Avatar answered Sep 21 '22 05:09

John Fisher