0

The following:

Regex.Matches("Some Text @param Some More", "(.*)(@param)(.*)")

returns

  • Some Text @param Some More
  • Some Text
  • @param
  • Some More

Is there any way to not have the first line? I cannot find any documentation on this. And, if I use online parsers, they only list the 3 groups...I would like to avoid having to code in the ignore first...

4

2 回答 2

2

Use a named group captures to not have to work with indexing. Change to this:

Regex.Matches("Some Text @param Some More", "(?<One>.*)(@param)(?<Two>.*)")

then access the match data such as

var data1 = mt.Groups["One"].Value;
var data2 = mt.Groups["Two"].Value;
于 2013-07-29T19:29:55.947 回答
1

Try this:

Regex.Matches("Some Text @param Some More", "^.*(?=@param)|@param|(?<=@param).*");
于 2013-07-29T19:16:33.717 回答