카테고리 없음

[씨#] 정규식을 사용하여 문장 분할

필살기쓰세요 2021. 1. 10. 07:26
using System.Text.RegularExpressions;
string[] parts = Regex.Split(mytext, "\.\n|\. "); 
# or "\.\s" if you're not picky about it matching tabs, etc.
-------------------

정규식

/\.\s/

.뒤에 공백이 오는 리터럴과 일치합니다 .

-------------------

이를 위해 정규 표현식이 필요하지 않습니다. 오버로드를 사용하면 string.Split문자열 배열이 필요합니다.

string[] splitters = new string[] { ". ", ".\t", "." + Environment.NewLine };
string[] sentences = aText.Split(splitters, StringSplitOptions.None);


출처
https://stackoverflow.com/questions/1904917