正则表达式在NLP中应用

  正则表达式是一种定义了搜索模式的特征序列  ,用于字符串的模式匹配。

它的作用有两个: (1) 将文档内容从非结构化转为结构化 , 以便文本挖掘

         (2) 去除“噪声”(即 文本片段中,与文本无关的文字信息和最终输出)

1. 匹配字符串

  re.search(regex,string )     检查string字符串是否匹配正则表达式 regex

  例1   获取包含“xx”的关键字的句子

  

    import re
    text_string='     '
    regex='xx'
    p_string=text_string.split(" ")  #通过  拆分
    for line in p_string:
        if re.search(regex,line) is not None:  #search查询匹配regex
            print(line)
原文地址:https://www.cnblogs.com/liulala2017/p/13512896.html