[英]Regex for splitting into sentences, ignoring decimal numbers as part of the split?
在 javascript 中,我有興趣將文本正文拆分為數組句子,其中它忽略了拆分的十進制數字(理想情況下是網站)。 我已經找到了如何處理句子 - 例如,
str.split(\/[\\.\\!]+\\s*|\\n+\\s*\/)<\/code> - 但不知道如何添加額外的位來忽略十進制數字在分裂中
例如,如果
str = "Hello there, the ice cream is $2.00.Toppings are extra."
str = "Hello there, the ice cream is $2.00.Toppings are extra.";
str.split(/[\.\!]+(?!\d)\s*|\n+\s*/); //[ 'Hello there, the ice cream is $2.00', 'Toppings are extra',]
(?!\\d)
零寬度負前瞻以匹配d
igit。如果前瞻匹配,則正則表達式不匹配且字符串不拆分。
斯卡拉:
import java.util.regex.Pattern;
var regPattern = "(?<!\\d)\\.(?!\\d)|(?<=\\d)\\.(?!\\d)|(?<!\\d)\\.(?=\\d)";
val pt = regPattern.compile(pattern);
var strList: List[String]= pt.split(input).map(_.trim)(breakOut)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.