I need to remove everything before the :
Active Scanning: Scanning IP Blocks
I just need to keep the Scanning IP Blocks
val = "Active Scanning: Scanning IP Blocks"
pos = val.rfind(':')
if pos >= 0:
val = val[:pos]
print(val)
But I'm getting the everything before the :
CodePudding user response:
[:pos]
means 0
to pos
which you don't want. write [pos 1:]
what will give you pos
to the end of the string.
val = "Active Scanning: Scanning IP Blocks"
pos = val.rfind(':')
if pos >= 0:
val = val[pos 1:]
print(val)
CodePudding user response:
You can try:
>>> import re
>>> val = "Active Scanning: Scanning IP Blocks"
>>> re.sub(r'^.*?:', '', val)
' Scanning IP Blocks'
CodePudding user response:
string[startIndex:endIndex] that is how it works. So you have to :
val = "Active Scanning: Scanning IP Blocks"
pos = val.rfind(':')
if pos >= 0:
val = val[pos 1:]
print(val)
or you can use split()
val = "Active Scanning: Scanning IP Blocks"
pos = val.rfind(':')
if pos >= 0:
val = val.split(":")[1]
print(val)