6
\$\begingroup\$

Your regex will receive a string of the form

!XX!

#<extra>

where X is any hexadecimal digit (0-9 and A-F capital letters only), and <extra> is a character sequence to your choosing. (perhaps something like 0123456789ABCDEF0 could be useful?)

You may use any regex flavour.

Scoring will be calculated as: find regex length + replace length + custom string length. lowest score wins.

Your submission must include which flavour you are using, the find regex, the replace string, and your extra string, all of their lengths, and the total length.

test cases:

!00!

#<extra>

Expected output:

!01!

#<extra>

!AC!

#<extra>

Expected output:

!AD!

#<extra>

!2F!

#<extra>

Expected output:

!30!

#<extra>

!FF!

#<extra>

Expected output:

!00!

#<extra>

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to the site. All questions must have a scoreable winning criterion. What is the winning criterion for this? Is it code/regex golf (shortest code)? \$\endgroup\$ Feb 22, 2022 at 21:19
  • 1
    \$\begingroup\$ @LevelRiverSt "Scoring will be calculated as: find regex length + replace length + custom string length. lowest score wins." \$\endgroup\$ Feb 22, 2022 at 22:39

3 Answers 3

2
\$\begingroup\$

Perl 5, 58 score: 21 + 2 + 17 = 40 bytes

Using PCRE substitution

s/(\w)(?=F?.
#.*?\1(.))/$2/g

with extra

0123456789ABCDEF0

Try it online!

First solution overcomplicated

s/(\w)(F)?(?=.
#.*?\1(.).*(?(2)F(.)))/$3$4/g

with extra

0123456789ABCDEF0F0
\$\endgroup\$
1
\$\begingroup\$

Retina 0.8.2, 20 + 2 + 17 = 39 bytes

(\w)(?=F*!¶¶.*\1(.))
$2

Try it online! Linked test suite automatically adds and removes the extra string.

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

Perl 5, 3+25+0 = 28

s/\w+/sprintf"%02X",1+hex$&&255/e

Try it online!

3 chars in \w+.

25 in sprintf"%02X",1+hex$&&255 where $& is the found input hex number.

0 extra chars after #.

\$\endgroup\$
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.