使用Python3.8查找文本中的正则表达式

2024-03-28 22:37:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用正则表达式从一些文本中提取一个钻孔编号的列表,但不能使正则表达式按预期工作。你知道吗

格式通常是两个大写字母,后跟一些不同长度的字符,例如BH1, WS01, BH001

偶尔以结尾的大写字母表示已重新钻孔,例如BH2301A是BH2301的重新钻孔。你知道吗

我能得到的最接近的结果是返回一个元组,但是我只需要返回第一个值。你知道吗

BH = re.compile(r'\w\w\d+')
BH.findall('4.9.26.9.2  A summary of rotary coring data from White Chalk (South) is provided in Table 37. Downhole geophysics (optical and acoustic televiewers) was undertaken on five boreholes in the LTC Pumping Tests investigation BH2313A, OH03001, OH03002, OH03003, OH04007 and OH04008. Televiewer data provides a more accurate assessment of fracture location and orientation than the associated core logging. This is because the borehole wall is less susceptible to drilling induced disturbance than the recovered core. An automated discontinuity picking algorithm within WellCAD© software was used by the contractor to identify features in the televiewer datasets. ')
['BH2313', 'OH03001', 'OH03002', 'OH03003', 'OH04007', 'OH04008']

BH = re.compile(r'(\w\w\d+(\w)?)')
BH.findall('4.9.26.9.2  A summary of rotary coring data from White Chalk (South) is provided in Table 37. Downhole geophysics (optical and acoustic televiewers) was undertaken on five boreholes in the LTC Pumping Tests investigation BH2313A, OH03001, OH03002, OH03003, OH04007 and OH04008. Televiewer data provides a more accurate assessment of fracture location and orientation than the associated core logging. This is because the borehole wall is less susceptible to drilling induced disturbance than the recovered core. An automated discontinuity picking algorithm within WellCAD© software was used by the contractor to identify features in the televiewer datasets. ')
[('BH2313A', 'A'), ('OH03001', ''), ('OH03002', ''), ('OH03003', ''), ('OH04007', ''), ('OH04008', '')]

元组输出是我用正则表达式所能期望的最好结果吗?我需要一个循环来把它们切块以返回第一组吗?你知道吗


Tags: andoftheincoredataisbh
1条回答
网友
1楼 · 发布于 2024-03-28 22:37:53

刚刚从得到的元组中提取了第一个值:

[x[0] for x in BH.findall('4.9.26.9.2  A summary of rotary coring data from White Chalk (South) is provided in Table 37. Downhole geophysics (optical and acoustic televiewers) was undertaken on five boreholes in the LTC Pumping Tests investigation BH2313A, OH03001, OH03002, OH03003, OH04007 and OH04008. Televiewer data provides a more accurate assessment of fracture location and orientation than the associated core logging. This is because the borehole wall is less susceptible to drilling induced disturbance than the recovered core. An automated discontinuity picking algorithm within WellCAD© software was used by the contractor to identify features in the televiewer datasets. ')]

相关问题 更多 >