相关疑难解决方法(0)

使用Regex进行句子分割

我有很少的短信(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.

python regex text-segmentation

2
推荐指数
1
解决办法
1346
查看次数

java:使用正则表达式提取字符串中的数字

我有一串格式"[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中进行这种模式匹配?

java regex matching

1
推荐指数
1
解决办法
1万
查看次数

你会如何编写一个与每三位数用逗号匹配的正则表达式?

它必须符合以下条件:

  • '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)

python regex

0
推荐指数
1
解决办法
241
查看次数

正则表达式只接受数字和十进制值而不是c#中的任何特殊或字符

如何限制文本框中的特殊字符和字符?我正在使用此代码,但我并不限制特殊字符和字符

代码: -

if (!Regex.IsMatch(((Windows.UI.Xaml.Controls.TextBox)sender).Text, @"^\\d*\\.?\\d*$"))
{
    // Write Code 

}
Run Code Online (Sandbox Code Playgroud)

c# asp.net wcf uwp

0
推荐指数
1
解决办法
201
查看次数

标签 统计

regex ×3

python ×2

asp.net ×1

c# ×1

java ×1

matching ×1

text-segmentation ×1

uwp ×1

wcf ×1