Python Copying part of string -



Python Copying part of string -

i have line

server:x.x.x.x # u:100 # p:100 # pre:0810 # tel:xxxxxxxxxx

and want re-create value 0810 after pre: value how can ?

you utilize re module ('re' stands regular expressions) solution assumes pre: field have 4 numbers. if length of number varies, replace {4}(expect 4) + (expect 'one or more')

>>> import re >>> x = "server:x.x.x.x # u:100 # p:100 # pre:0810 # tel:xxxxxxxxxx" >>> num = re.findall(r'pre:(\d{4})', x)[0] # re.findall returns list >>> print num '0810'

you can read here:

https://docs.python.org/2/howto/regex.html

python string copy

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -