[英]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.