I have a line as shown below:
s = 'hello\n this is\n a forum\n'
And I use regex to get every single / double occurrence of each character. I want to create a list likeli = [ 'h','e','ll','o','\n','t','h'....]
I used
pattern = re.compile(r'(.)\1?' , re.IGNORECASE)
newList = [m.group() for m in pattern.finditer(s)]
print newList
But it gave me newList= [ 'h','e','ll','o','t','h'....], here I could not get the character "\ n" of a new line. How do I change my patter to get "\ n" in my list?
source
share