-1

The function would be:

def split_string(string, removal)

For example, if I have the string ABCDEFGHIJK and removal string DEF, the program would remove DEF from the string and return the LEFT and RIGHT resulting strings. In this case, it would be ABC and GHIJK.

How would I go about doing this using Regex? One idea I had was to find the target "removal" string in the original string and replace it with a space, then parse that string and return the two strings.

user3874530
  • 55
  • 1
  • 2
  • 7

2 Answers2

0

you can simply do

str = "ABCDEFGHIJK";

print str.split("DEF");

see the online compiler

marvel308
  • 10,288
  • 1
  • 21
  • 32
0

I'm not sure how (or why) you would do that with a regex. This is a much simpler solution.

def split_string(string, removal):
    return string.split(removal)

leftString, rightString = split_string("abcdefghijk", "def")
Aaron
  • 192
  • 6