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

4 of 6
deleted 3 characters in body
math junkie
  • 7.3k
  • 1
  • 23
  • 47

Retina, (削除) 291 (削除ここまで) 286 bytes

.*
$u
Pot
K
op
u
Iro
Fe
Silv
Ag
Tin
Sn
0L`.*f|[RS].*g|Ast|Ch.|Flu|Ge|Lawr|Ma.|Me..|N[ei]o?[bdpt]|Pla?.|Pro.a?|Radon|Str|Thal|Unun.|Zi.|[ACEH].*s|[BDLRST].[bcehmv]|[CGP]a.*d|..+r[bkmn]s?|[CT]h?u.*m|..
\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|[RS].*g|Ast|Ch.|Flu|Ge|Lawr|Ma.|Me..|N[ei]o?[bdpt]|Pla?.|Pro.a?|Radon|Str|Thal|Unun.|Zi.|[ACEH].*s|[BDLRST].[bcehmv]|[CGP]a.*d|..+r[bkmn]s?|[CT]h?u.*m|..

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 によって変換されたページ (->オリジナル) /