0
can anyone tell me why it is giving none?
it is supposed to print the last line. but it giving none. i mean, it is supposed to print the line with whitespaces. the code says, begin with X- and print the line with white spaces upto : (this colon) https://code.sololearn.com/cxvgTmDmifwV/?ref=app
9 Antworten
+ 1
re.search returns a Match object which contains the matched characters and positions of the matched characters
and your search expressions is wrong..
it should be re.search(r"X-+",j);
+ 1
Мг. Кнап🌠 the code says, begin with X- and print the line with white spaces upto : (this colon)
+ 1
Mr. 12 no this expression (r"^X-\S*:") says to look for character X and - and just after that look for one or more non space character. So yes it didn't got any space so it matchers upto colon.
But the expression (r"X-\s*:") didn't worked because after X- it didn't got any space nor any colon, instead it got alpha characters.. that's why it printed None
So you have to look for alpha groups after the X-
so for last condition this should work :
re.search(r"^X\S+\s([^:]*)(?=:)",h);
https://code.sololearn.com/cM53bZlY7USy/?ref=app
0
Mr. 12 so what exactly do you want to achieve in this Code?
0
Мг. Кнап🌠 \s+ is supposed to search for only the line with whitespaces right?
so i want to print the line with only whitespaces, not the above two lines.
0
All the statements have white spaces.. which part of the string you want to print
0
Мг. Кнап🌠 No bro,
i, j has '-' in between the words upto ':'
but k has only white spaces.
watch the code clearly.
and if we put capital S in the place of small s
it is not printing k because k has whitespaces.
put when we put small s, it has to ignore i, j and it has to print k, because k has white spaces.
0
Ok, this is what I was asking.. u did not mentioned about the colon ( : ) as seperator...
So u could do like :
print(bool(re.search(r"\s",k.split(":")[0])))
0
Мг. Кнап🌠 watch this code, it is printing upto ':'
i just changed it by replacing 'S' with 's'.
which means the line with white spaces.
but it is printing None.
h becomes None because it has whitespaces.
i want to print h
https://code.sololearn.com/c4SeF8WHsyH5/?ref=app