簡體   English   中英

Python正則表達式在破折號之間查找字母字符串

[英]Python regex to find alpha strings between dashes

我有一系列的字符串看起來都差不多。

- Conf. w/attorney, defendant, bondsman. Magistrate ct., PA - Research - 2.7 hrs - 86 miles

我需要寫一個與

- Conf. w/attorney, defendant, bondsman. Magistrate ct., PA -

- Research -字符串的一部分。

但不是hrsmiles段。

x = re.findall('-[.^\\-0-9]*-', line)

到目前為止,我一直在嘗試這種方法,但是不會返回任何匹配結果。

我確定我只是在寫RE錯誤。

如果要使用Regex進行操作,可以嘗試:

r'.*?(?= \d)'

檢查: https//regex101.com/r/uG0fI2/3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM