我有很少的短信(SMS)消息,我想用句点('.')作为分隔符对它们进行分段.我无法处理以下类型的消息.如何在Python中使用Regex对这些消息进行分段.
分割前:
'hyper count 16.8mmol/l.plz review b4 5pm.just to inform u.thank u' 'no of beds 8.please inform person in-charge.tq'
分割后:
'hyper count 16.8mmol/l' 'plz review b4 5pm' 'just to inform u' 'thank u' 'no of beds 8' 'please inform person in-charge' 'tq'
每行都是单独的消息
更新:
我正在进行自然语言处理,我觉得可以对待'16.8mmmol/l'并且'no of beds 8.2 cups of tea.'同样如此.80%的准确度对我来说已足够,但我希望尽可能减少False Positive.
我有一串格式"[232] ......."我想从字符串中提取232,我做了这个
public static int getNumber(String str) {
Pattern pattern = Pattern.compile("\\[([0-9]+)\\]");
Matcher matcher = pattern.matcher(str);
int number = 0;
while (matcher.find()) {
number = Integer.parseInt(matcher.group());
}
return number;
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我得到以下例外:
Exception in thread "main" java.lang.NumberFormatException: For input string: "[232]"
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何解决这个问题,如果有一种更有效的方法让我在java中进行这种模式匹配?
它必须符合以下条件:
'42'
'1,234'
"6368745"
但不是以下内容:
'12,34,567'(逗号之间只有两位数)
'1234'(缺少逗号)
我在python 3中编写了以下python程序.我在这里做错了什么?它给出了AttributeError
import re
numRegx = re.compile(r"""^
(\d{1,3}(\,))? # optional first three digits and comma (1,)
((d{3})(\,))* # optional Second three digits and comma (345,)
\d{3}$ # Last three digits (456)
""", re.VERBOSE)
mo = numRegx.search('1,345,456')
print(mo.group())
Run Code Online (Sandbox Code Playgroud) 如何限制文本框中的特殊字符和字符?我正在使用此代码,但我并不限制特殊字符和字符
代码: -
if (!Regex.IsMatch(((Windows.UI.Xaml.Controls.TextBox)sender).Text, @"^\\d*\\.?\\d*$"))
{
// Write Code
}
Run Code Online (Sandbox Code Playgroud)