Regex - match everything but this pattern (and first and last)
I am trying to adjust the pattern of DNS data to match something that looks like a DNS address. In this case I have a string that looks like this.
I would like to change that to an actual DNS name, as follows:
Is there a regex expression that would be able to do this?
This could be done in two steps.
Use this regex and replace with nothing.
^\(\d+\)|\(\d+\)$ This will replace the first and last (number) with empty string. Demo here
Use this regex and replace with a dot.
\(\d+\) This will replace every occurrence of (number) with dot. Demo here
Since there is no indication of regex environment. I'm assuming it's python.
import re data = "(19)espnfivethirtyeight(5)files(9)wordpress(3)com(0)" rx = re.compile(r"\(\d+\)") print('.'.join([x for x in rx.split(data) if x!='']))
based on input string, it will print: