Jul-03-2018, 01:28 PM
Hi guys,
Trying to a simple match with a variable input.
* list1['30 dfa00','NOPE 223123','41 53452','XX 123453','342']
* variable ...could be anything.
Basicly it should do something like:
if list1 starts with variable: remove those characters, return the rest of the string else return full string.
Trying to a simple match with a variable input.
* list1['30 dfa00','NOPE 223123','41 53452','XX 123453','342']
* variable ...could be anything.
Basicly it should do something like:
if list1 starts with variable: remove those characters, return the rest of the string else return full string.
import re # the variable is ALWAYS [number][number][space] # prog = re.compile('(0-9)+( )') list1=['30 dfa00','NOPE 223123','41 53452','XX 123453','342'] output=[] for l in list1: if prog.match(l): output.append(l.split(3)[1]) else: output.append(l) print(output) #should return #dfa00, NOPE 223123, 53452, XX 123453, 342What am I doing wrong?
import re # the variable is ALWAYS [number][number][space] # prog = re.compile("([0-9]+)+( )") list1=['30 dfa00','NOPE 223123','41 53452','XX 123453','342'] output=[] for l in list1: if prog.match(l): output.append(l.split(3:)) else: output.append(l) print(output) #should return #dfa00, NOPE 223123, 53452, XX 123453, 342Hmmm this is what I have now ... and it seems to work. Good approach?