简体   繁体   English

基于正则表达式的字符串拆分

[英]String splitting based on Regular Expressions

I am trying to split a string which looks like this: 我正在尝试拆分一个看起来像这样的字符串:

1.2.1Title of the Chapter

(There is no space between '1' and 'T') (“ 1”和“ T”之间没有空格)

I want the output as: 我希望输出为:

String 1: 1.2.1
String 2: Title of the chapter

I tried this: 我尝试了这个:

strParagraphs = 1.2.1Title of the chapter;
string[] lines1 = Regex.Split(strParagraphs, "(\\d{1}).(\\d{1}).(\\d{1})");
also
string[] lines1 = Regex.Split(strParagraphs, "^\\w+");

I could not arrive at my desired output. 我无法达到所需的输出。 Can someone please suggest, where is it that I am going wrong? 有人可以建议我错了吗?

Many thanks 非常感谢

This should work like a charm: 这应该像一种魅力:

string[] lines = Regex.Split(inputstring, @"(\d+.\d+.\d+)");

Result: 结果:

1.2.1 
Title of the Chapter 

Note: the result may differ depending on .net version! 注意:结果可能因.net版本而异!

For further information, please see: 有关更多信息,请参见:
Regex.Split Method (String, String) Regex.Split方法(字符串,字符串)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM