Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

1 of 6
math junkie
  • 7.3k
  • 1
  • 23
  • 47

Retina, 295 bytes

.*
$u
Pot
K
opp
u
Iro
Fe
Silv
Ag
Tin
Sn
0L`.*f|..+r[bk]|[RS].*g|Ast|Ch.|Flu|Lawr|Ma.|Me..|N[ei]o?[bdpt]|Pla?.|Pro.a?|Str|Thal|Unun.|Zi.|[ACEH].*s|[BDLRST].[bcehmv]|[CGP]a.*d|[CR]o?...n|[CT]h?u.*m|[DF].rms?|..
\B.*\B
T`l``[FHKNOSVY][at-y]|Cb|Bo|Io|Ph|Ur
So
Na
An
Sb
Tu
W
Go
Au
Mc
Hg
Le
Pb
U.
U$l

Try it online!

Verification script (Python)

Explanation

.*
$u

Convert the first letter of the input to uppercase and the rest to lowercase.

0L`.*f|..+r[bk]|[RS].*g|Ast|Ch.|Flu|Lawr|Ma.|Me..|N[ei]o?[bdpt]|Pla?.|Pro.a?|Str|Thal|Unun.|Zi.|[ACEH].*s|[BDLRST].[bcehmv]|[CGP]a.*d|[CR]o?...n|[CT]h?u.*m|[DF].rms?|..

Truncate each element name, ending with the intended second letter. The default case .. matches the first two letters of the element name.

\B.*\B

Keep only the first and last letter.

T`l``[FHKNOSVY][at-y]|Cb|Bo|Io|Ph|Ur

Remove the lowercase letters from the single-letter abbreviations.

U.
U$l

Insert the u for the elements that require it.


The rest of the program deals with various special-case replacements. Some of these occur before the main regex because those elements share their first two letters with another.

math junkie
  • 7.3k
  • 1
  • 23
  • 47

AltStyle によって変換されたページ (->オリジナル) /