• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

Splitting on an asterisk using a regular expression

Is there a way to split a string by an asterisk using a regular expression in C#?
  • 2
1 Solution
To use an asterisk in a regular expression, escape it with a backslash (the backslash, of course, needs to be escaped in c#, resulting in the code "\\*" or @"\*"):

  string input = "A*B*C";
  string[] output = System.Text.RegularExpressions.Regex.Split(input, "\\*");
  //output = string[] { "A", "B", "C" }

You can also use the String.Split method in this case:

  output = input.Split('*');
jeshbrAuthor Commented:
for some reason the Regex.Split does not work.

but the string.Split works fine.
jeshbrAuthor Commented:

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now