1
\$\begingroup\$

Your Challenge

You must write a program/function etc. that takes a domain name of a StackExchange site and outputs the domain for the meta version of the site passed to it. Examples:

stackoverflow.com => meta.stackoverflow.com
codegolf.stackexchange.com => codegolf.meta.stackexchange.com
mathoverflow.net => meta.mathoverflow.net   
codereview.stackexchange.com => codereview.meta.stackexchange.com

Note: Subdomains are added to meta.stackexchange.com. Separate domains have meta. prepended. You don't need to worry about stackexchange.com or meta.stackexchange.com passed.

Shortest answer in bytes wins!

\$\endgroup\$
6
  • \$\begingroup\$ Why post basically the same question within 10 mins? I know that ones a polyglot but is there really any purpose or difference from the other one? \$\endgroup\$
    – user67719
    Apr 6, 2017 at 0:17
  • 1
    \$\begingroup\$ Could you provide the specification rather than just saying it is defined by SE? Or a link to the logic used? \$\endgroup\$ Apr 6, 2017 at 0:20
  • 1
    \$\begingroup\$ @JonathanAllan Subdomains are added to meta.stackexchange.com. Separate domains have meta. prepended. \$\endgroup\$
    – user58826
    Apr 6, 2017 at 0:22
  • 1
    \$\begingroup\$ -1 for no specification. \$\endgroup\$
    – feersum
    Apr 6, 2017 at 1:59
  • 1
    \$\begingroup\$ I'm fairly sure there are exceptions not covered by the examples. E.g. isn't meta.stackexchange.com it's own meta site? \$\endgroup\$ Apr 6, 2017 at 5:57

8 Answers 8

1
\$\begingroup\$

Retina, 17

\w+\.\w+$
meta.$&

Try it online.

\$\endgroup\$
1
\$\begingroup\$

GNU Sed, 20

Score includes +1 for use of -r.

s/\w+\.\w+$/meta.&/

Try it online.

\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6), 41 40 34 32 bytes

s=>s.replace(/\w+\.\w+$/,'meta.$&')

<input id=a oninput="b.innerText=a.value.replace(/\w+\.\w+$/,'meta.$&')"/>
<p id=b />

\$\endgroup\$
1
\$\begingroup\$

Pip, 21 20 bytes

aR`\w+.\w+$``meta.&`

Try it online!

Matches the last two runs of word characters (separated by some other character), to which it prepends meta..

\$\endgroup\$
1
\$\begingroup\$

Python 2, 57 54 bytes

l=input().split(".");l[:-2]+=["meta"];print".".join(l)

Try it online!

Split on periods, insert "meta" before the second item from the end, join the list again on periods and print.

\$\endgroup\$
0
\$\begingroup\$

JS (ES6), 59 bytes

m="meta.",a=>a.split(".").length-2?a.replace(/\./,"."+m):m+a

If the string passed to the function expression has more than 1 . in it, a .meta. is inserted in the first .. Otherwise, meta. is appended to that string.

\$\endgroup\$
0
\$\begingroup\$

Jelly, 22 19 bytes

ṣ”.ṙ-2;“£2v»W¤ṙ2j”.

Try it online!

How?

ṣ”.ṙ-2;“£2v»W¤ṙ2j”. - Main link: domain string
ṣ”.                 - split at occurrences of '.'
   ṙ-2              - rotate right by -2
             ¤      - nilad followed by link(s) as a nilad
       “£2v»        -     dictionary lookup of "meta"
            W       -     wrap in a list
      ;             - concatenate
              r2    - rotate right by 2
                j”. - join with '.'s
\$\endgroup\$
0
\$\begingroup\$

PHP, 48 Bytes

echo preg_filter("#\w+\.\w+$#","meta.$0",$argn);

but we should better do it like this

echo strstr($argn,"meta.")?$argn:preg_filter("#\w+\.\w+$#","meta.$0",$argn);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.