Question: So I'm making a voice assistant in Python and I want it to do math that I input. This code checks if it ends with an integer:

```
    elif text[-1].isdigit() == True:

            basicmath()

```

Then the function basicmath():

```
def basicmath():

    split = text.split(" ")
    in1 = split[0]
    in2 = split[5]
    op = split[3]
    print(op)

    if op == "+":

        m = in1+in2
        worked = "y"
        mathout = str(m)
        print(mathout)

    elif op == "-":

        m = in1-in2
        worked = "y"
        mathout = str(m)
        print(mathout)

    elif op == "*":

        m = in1*in2
        worked = "y"
        mathout = str(m)
        print(mathout)

    elif op == "/":

        m = in1/in2
        worked = "y"
        mathout = str(m)
        print(mathout)

```

My terminal doesn't return any errors, it just doesn't run the lines where you assign the variables in1, in2, and op. I really just need to know how to pull lines from the list made by split(). Please keep in mind that I'm still learning Python. Thank you!

Answer: 
Use `perl=TRUE` with [lookaround](https://www.regular-expressions.info/lookaround.html):

```r
vec <- c("2 - 5-< 2", "6 - 10-< 2", "6 - 10-2 - 5", "> 15-2 - 5")
strsplit(vec, "(?<! )-(?!= )", perl=TRUE)
# [[1]]
# [1] "2 - 5" "< 2"  
# [[2]]
# [1] "6 - 10" "< 2"   
# [[3]]
# [1] "6 - 10" "2 - 5" 
# [[4]]
# [1] "> 15"  "2 - 5"

```
I guess this is an easier-to-understand solution:

```
library(stringr)
str_split(vec, "(?<=\\d)-(?=\\d)")
[[1]]
[1] "2 - 5" "< 2"  

[[2]]
[1] "6 - 10" "< 2"   

[[3]]
[1] "6 - 10" "2 - 5" 

[[4]]
[1] "> 15"  "2 - 5"

```

First off, no `perl = TRUE` needed (well, but a new package, `stringr`).
But then, `(?<=\\d)` and `(?=\\d)` are **positive** lookarounds, which are inherently easier to process. The first means: if you see a digit on the left ...; the second says, if you see a digit on the right ... And `str_split`(with the underscore) says, if these two conditions are met, then split on the dash `-`.