String Powershell-之间的差异结果;“字符串”-拆分和;字符串";。拆分()而不松开分隔符
我正试着把句子从字符串中分离出来。我在堆栈溢出上发现了以下内容:String Powershell-之间的差异结果;“字符串”-拆分和;字符串";。拆分()而不松开分隔符,string,powershell,split,String,Powershell,Split,我正试着把句子从字符串中分离出来。我在堆栈溢出上发现了以下内容: $stringToExtract = "sentence a. sentence b. sentence c. last phrase" $mySentences = $stringToExtract -split "(?<=\.)" $mySentences sentence a. sentence b. sentence c. last phrase $stringToEx
$stringToExtract = "sentence a. sentence b. sentence c. last phrase"
$mySentences = $stringToExtract -split "(?<=\.)"
$mySentences
sentence a.
sentence b.
sentence c.
last phrase
$stringToExtract=“句子a.句子b.句子c.最后一句话”
$mycentenses=$stringToExtract-split“(?-split
是使用正则表达式的运算符。(?-split
是使用正则表达式的运算符。(?-split
和其他操作符,如-match
和-replace
使用正则表达式,而.match
.replace
和.split
不使用正则表达式。此外,如果您对.split()
方法的结果感到满意,只需将其简化为.split('.'))
为简洁起见。感谢所有的评论。我非常感谢。@AdminOfThings如果它们真的是一个句子,我想在句子末尾保留点。顺便说一下,我正在从字符串中提取句子。嘿,你能帮我构建一个正则表达式来从行中提取这部分句子吗:“从满天繁星的天空,一个宽阔的视野下到一座宏伟的城堡,城堡上有一个“…”
有一个“n点”
:一个,两个,…
或。
最后我想把它们都包括进去。我试过了$mycentenses=[regex]::Split($stringToExtract),(?
$stringToExtract = "sentence a. sentence b. sentence c. last phrase"
$mySentences = $stringToExtract.split("(?<=\.)")
$mySentences
sentence a
sentence b
sentence c
last phrase
$stringToExtract = "sentence a. sentence b. sentence c. last phrase"
$mySentences = $stringToExtract -split "(?<=\.)"
$mySentences = [regex]::Split($stringToExtract,'(?<=\.)')