简体   繁体   English

如何使用python从文本中提取单词?

[英]How to extract words from a text using python?

I need to extract the words and phrases within a text. 我需要提取文本中的单词和短语。 For example, the text is: 例如,文本为:

Привет, hello, как дела? english word, еще одно русское слово, слово-1224, тест 4456

And script should return the following: 并且脚本应返回以下内容:

Привет
как
дела
еще
одно
русское
слово
слово-1224

That is, I need to take from the text of all the words that begin with the Russian letters ( [а-яА-Яё-] ), and can contain numbers and letters of the Russian alphabet. 也就是说,我需要从所有以俄语字母( [а-яА-Яё-] )开头的单词的文本中[а-яА-Яё-] ,并且可以包含俄语字母的数字和字母。 How is this implemented? 如何实施?

It was a little bit trickier than I thought. 这比我想的要棘手。 Have never used cyrrilic chars. 从未使用过西里尔字符。 I do believe this should do: 我确实认为这应该做到:

text =  # Set you're input unicode string here.
words = re.findall('[\p{IsCyrillic}][0-9\p{IsCyrillic}]+', text)

for word in words:
    print word

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用正则表达式从 python 中的文本中提取特定单词 - Extract specific words from text in python using regular expression 如何使用 Python 计算 pdf 中文本摘录列表中的单词数? - How to count the number of words from a list from a text extract in a pdf using Python? 如何使用 python 从 pdf 的每个超链接中提取锚文本/单词? - How to extract anchor text/ words from every hyperlinks from pdf using python? 如何从Python的文本中提取A到L字母开头的单词? - How to extract words starting with letters from A to L from a text in Python? 如何从python中的文本中提取仅包含字母的单词? - How to extract words containing only letters from a text in python? 使用python从文本文件中提取单词 - Extract words from text files with python 如何使用 python 从 .txt 文件中提取随机词? - How to extract random words from .txt file using python? 如何在python中使用单个正则表达式从tweet中提取所有单词? - How to extract all words from tweet using single regex in python? 如何使用 Python 和 re 从字符串中提取准确的单词? - How to extract exact words from a string using Python and re? 如何使用 python 中的正则表达式从字节中提取单词? - How to extract words from bytes using regex in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM