I'm new to regex and python in general. I encountered some problems while practicing with regex. I don't quite understand how does python search the patterns. So, I did write code and in my mind, it should work fine, but it's returning None.
So, the string must start with any character "\w" and then it it continues. The string must have any character that is not digit in the end, so when python starts searching, it should find "j" at first, then "o", then "e", then it encounters space and must stop since it is not a digit character "\D"$. But the code returns None. What am I doing wrong?
import re
string = "joe 10 15 20 30 40"
strRegex = re.compile(r"\w(.*)\D$")
mo = strRegex.search(string)
print(mo)
The second thing I'm struggling with is grouping. What I'm trying in the code below is to find all matches that start with a word character and ends with comma. So basically, output should be first and second sentence separately, but it's not working either.
string = "The generated Lorem Ipsum is therefore always free from repetition, injected humour,"
stringRegex = re.compile(r"(^\w.*,$)")
mo = stringRegex.findall(string)
print(mo)
Any help would be much appreciated.