How do I match everything before a string with a RegEx

I need help creating a regular expression that matches any possible character up until a certain point.

I.e supposing I have the text

Hi my name is john… my email is hdjjkd@cdc.com i like playing sports etc

How do I write an expression that would match everything up to cdc.com ?

I need the expression to allow me to match a phrase to end with.
Hopefully this makes sense… Any Ideas??

I’m not entirely sure what you’re getting it, but maybe something like^(.*?cdc\\.com) ?

Hmm I think that is close… I am using gskinner.com/RegExr and it doesn’t seem to be quite right…

I basically need to match eveything from ‘I need’ to ‘cdc.com’ Does that help?

Works for me if I check “dotall” :slight_smile:

import re

my_str = """Hi my name is John...
My email is hdjjkd@cdc.com.  I like playing
sports.
"""

endings = [
    "John",
    "hdjjkd@cdc.com",
    "playing"
]

for ending in endings:
   esc_ending = re.escape(ending)
   result = re.match(".*?" + esc_ending, my_str, re.X|re.M|re.S)
   if result:
       print(result.group(0))
       print("~" * 30)

--output:--
Hi my name is John
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi my name is John...
My email is hdjjkd@cdc.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi my name is John...
My email is hdjjkd@cdc.com.  I like playing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~