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.

(19)espnfivethirtyeight(5)files(9)wordpress(3)com(0)

I would like to change that to an actual DNS name, as follows:

espnfivethirtyeight.files.wordpress.com

Is there a regex expression that would be able to do this?

Answers


This could be done in two steps.

  1. Use this regex and replace with nothing.

    ^\(\d+\)|\(\d+\)$ This will replace the first and last (number) with empty string. Demo here

  2. 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:

espnfivethirtyeight.files.wordpress.com

Need Your Help

Media queries strange behaviour

media-queries

I've got following media-queries rules:

Replacement for <center>

html css deprecated

This has been asked before by other people, but I've never seen an adequate answer. Is there a valid replacement to the &lt;center&gt; tag?