Python search and replace ip address -
i want use re.sub search , replace whatever ip address specific ip address using python example in file has
address = 192.168.1.1 or address = 1.1.1.1 or address = fe0c::1 keyword address =, rest of wildcard. want convert address = 2.2.2.2 or address = f870:2:2:2::1 . destination specific address. seemed me use re.sub simple, not mind use others
thanks
tom
try this:
#line whatever string you're trying replace re.sub("address = \s+", "address = 2.2.2.2", line) you call re.sub 3 parameters: re.sub(pattern, replacement, string_to_replace), pattern regular expression indicating want replace.
in our case pattern "address = \s+", saying match characters "address = " followed 1 or more non-whitespace chars. when re finds part of string matching pattern, replaces string put in replacement parameter, i.e. "address = 2.2.2.2".
Comments
Post a Comment