I have a two strings:
num = '#123'
line = '#123 random text generator #111 #222 #333'
I wish to get all the numbers of the format '#xyz' if num == first number in line.
I've used regex to get the first number (#123) by:
re.findall(r'[#]\d{3,10}', line)
and I try to test this condition by:
if re.findall(r'[#]\d{3,10}', line)[:1] == num:
I've tried to get the re.findall into a parameter and print its length and type, and it says it's length 0 and type list. It's confusing me because [:1] should give me the '#123' string that it finds right? It seems like the list is empty but I can't figure out why.
More specifically my code has matrix = [['#123'] ['#234'] ['#345'] ['#666']].
def test(matrix,txt):
for num_group in matrix:
print num_group
for num in num_group:
for line in txt:
if re.findall(r'[#]\d{3,10}', line)[:1] == num:
print "found some more numbers in the line number!"
print line
more_nums = re.findall(r'[#]\d{3,10}', line)[1:]
matrix[num_group].append(nums)
So my end result should append #111 #222 and #333 to the matrix[0] that contains #123.
re?num? Is it a string? Right now it looks like a comment.