简体   繁体   中英

Regex to FindAll chains of strings until a dot with python

I need the regex expression gives to me the word before the : and all until a . The right output will be

['Socios: Norberto Alejandro PERONACE, 16/8/1973', 'Joaquin: jaja']

Here is my code:

text = "Esc. 7, Fº 10, 14/1/2019, Esc. M. Paula Corallo, Reg. 1525, Socios: Norberto Alejandro PERONACE, 16/8/1973. Joaquin: jaja."

if re.findall(r":", text):
    print(re.findall(r"\w+: \w+.\Z", text))
else:
    print("Match not found")

You may use

re.findall(r'\S+:[^.]+', text)

See the regex demo

Details

  • \\S+ - 1+ non-whitespace chars
  • : - a colon
  • [^.]+ - 1+ non-dot chars.

See also the Python demo .

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