简体   繁体   中英

Python regex to find alpha strings between dashes

I have a series of strings that all look roughly like this.

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

I need to write a regular expression that matches the

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

and - Research - parts of the string.

But not the hrs and miles segments.

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

Is what I've tried so far, but that doesn't return any matches.

I'm sure I'm just writing the RE wrong.

If you want to do it using Regex, you can try:

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

Check: https://regex101.com/r/uG0fI2/3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM