1

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")
2
  • And what's wrong with your code? Commented Sep 5, 2019 at 18:57
  • it's cut the output to the first word instead of continiuos to the dot @Sweeper Commented Sep 5, 2019 at 18:59

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.