简体   繁体   English

如何使用 python 从内容中提取特定单词

[英]How to extract a particular word from a content using python

I am new to python and i am trying to extract particular word from the content below starting with letter B and its following 10 characters.我是 python 的新手,我正在尝试从以下内容中提取特定单词,以字母 B 及其以下 10 个字符开头。 Example as shown below.示例如下图所示。

"FnSku/X-label from the item:na "来自项目的 FnSku/X-label:na

Incorrect value: BXXXXXXXXA不正确的值: BXXXXXXXXA

Correct (if available):na正确(如果有):na

Condition of the part(Used/New?): new零件状况(二手/新?):新

Purchase order:na"采购订单:na"

I am looking to extract the word BXXXXXXXXA.我正在寻找提取单词 BXXXXXXXXXA。 I tried to split the content and find the word that startswith 'B' however since word does not start with B i am unable to extract the same.我尝试拆分内容并找到以“B”开头的单词,但是由于单词不以 B 开头,因此我无法提取相同的单词。

Note: the content is not always the same but the count of letter starting with B is always 10.注意:内容并不总是相同,但以 B 开头的字母数总是 10。

Please help !请帮忙 !

It's possible with regular expression:使用正则表达式是可能的:

import re

 Words_starting_by_B= re.findall("B\w{9}", text)

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

相关问题 如何使用 python 从 word 文件中提取特定数据 - How to extract a particular data from word file using python 如何使用 Python NLP 从句子列表中提取特定单词。 这些词是医疗设备的零件 - How to extract particular word(s) from the list of sentences using Python NLP. These word(s) are Parts of Medical equipments 如何在 python 中的特定单词之后提取 substring? - How to extract substring after particular word in python? 使用Python提取一行中特定位置的特定单词 - Extract a particular word at a particular position in a line using Python 使用python从网页中提取在特定单词之后的单词 - Extract a word that follows a particular word from a webpage with python 如何使用Opencv和Python从视频流中提取特定帧 - how to extract a particular frame from video stream using Opencv & Python 如何使用 python 从记事本中提取或解析特定的文本行? - How to extract or parse particular line of text from notepad using python? 如何使用python从文本文件中提取特定行 - How to extract particular line from text file using python 如何使用python从文本中提取准确的单词? - How do I extract an exact word from text by using python? 如何使用regex从Python的Word文档中提取问题 - How to extract questions from a word doc with Python using regex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM