Regex for Finding Radioactive Elements

10

2

Find the shortest regex that matches all radioactive elements and nothing else in the Periodic Table of Elements.

Radioactive Elements

'Technetium','Promethium','Polonium','Astatine','Radon','Francium','Radium','Actinium','Thorium','Protactinium','Uranium','Neptunium','Plutonium','Americium','Curium','Berkelium','Californium','Einsteinium','Fermium','Mendelevium','Nobelium','Lawrencium','Rutherfordium','Dubnium','Seaborgium','Bohrium','Hassium','Meitnerium','Darmstadtium','Roentgenium','Copernicium','Ununtrium','Flerovium','Ununpentium','Livermorium','Ununseptium','Ununoctium'

Non-radioactive Elements

'Hydrogen','Helium','Lithium','Beryllium','Boron','Carbon','Nitrogen','Oxygen','Fluorine','Neon','Sodium','Magnesium','Aluminium','Silicon','Phosphorus','Sulphur','Chlorine','Argon','Potassium','Calcium','Scandium','Titanium','Vanadium','Chromium','Manganese','Iron','Cobalt','Nickel','Copper','Zinc','Gallium','Germanium','Arsenic','Selenium','Bromine','Krypton','Rubidium','Strontium','Yttrium','Zirconium','Niobium','Molybdenum','Ruthenium','Rhodium','Palladium','Silver','Cadmium','Indium','Tin','Antimony','Tellurium','Iodine','Xenon','Caesium','Barium','Lanthanum','Cerium','Praseodymium','Neodymium','Samarium','Europium','Gadolinium','Terbium','Dysprosium','Holmium','Erbium','Thulium','Ytterbium','Lutetium','Hafnium','Tantalum','Tungsten','Rhenium','Osmium','Iridium','Platinum','Gold','Mercury','Thallium','Lead','Bismuth'
  • Scored by character count in the regex.
  • Use standard Perl regex (just no specialized functions).
  • Assume all lower case.
  • You only need to count the characters of the regex itself.

Note if you used a program to get you started and maybe post how well it did. I'll post my best attempt as an answer to get started/show an example.

qw3n

Posted 2014-01-08T21:31:34.413

Reputation: 733

@qw3n You could say “regular expression describing a regular language” to exclude all the language specific things. – FUZxxl – 2015-03-08T11:58:53.840

Can you quote a regex standard, such as POSIX regular, POSIX extended, PCRE…? Otherwise "language agnostic" doesn't really mean much. – Tobia – 2014-01-08T21:55:29.727

Sorry, I have only had to use regex in java and javascript and don't really know all the differences. The goal is to create a regex that would work in most common languages without relying on language specific feature. – qw3n – 2014-01-08T22:02:06.473

There is an ongoing discussion as to whether we want regex golf on this site. Please contribute.

– Peter Taylor – 2014-01-08T23:48:09.913

Answers

3

Char count 59

e.+[hktv]|oh?r.+m|p...?o|r.*ci|be?.i|^c?u|rad|sta|has|ct|fe

Found via a mix of manually selecting good parts and running Peter Norvig's golfer on the remaining items.

Regex101 link

Sp3000

Posted 2014-01-08T21:31:34.413

Reputation: 58 729

LOL accepted answer after over 2 years! Imagine that @drjimbob's answer was the previous accepted answer. *3 characters better than accepted answer!*

– Erik the Outgolfer – 2016-05-31T18:28:25.757

For pete's sake! I've had the best answer for more than a year, and then I make it even better, and then you come along and do even better and get accepted! – EMBLEM – 2016-06-01T01:30:16.130

10

Char Count 61

lon|ct|oh|^ra|...t.+i|^c?u|or.+u|r.+c.|e..+e|f.?e|^h?as|be*.i

One 3 characters better than accepted answer!

63-character solution found with Peter Norvig's Regex golf solver. 61-character improvement found by a personal rewrite of that program in Go.

EMBLEM

Posted 2014-01-08T21:31:34.413

Reputation: 2 179

4

Char count 64

^(c?u|ra|no)|e.[kht]|[^l][gecv]i|[^c]oh?[rn]iu|f.r|ac|sta|bn|has

Should note, used parts of qw3n solution to reduce down my solution. Also used Peter Taylor's suggestion to trim two characters.

dr jimbob

Posted 2014-01-08T21:31:34.413

Reputation: 336

I have a feeling this is pretty near if not an optimal solution. Wish I'd seen that f.r part. :) – qw3n – 2014-01-10T01:05:40.493

1There's an easy 1-char saving by grouping everything anchored on ^, and another by changing ^(u|cu|...) into ^(c?u|...) – Peter Taylor – 2014-01-10T09:46:19.537

3

Char count 69

^u|e.[kht]|[^l][gecv]i|[^c]oh?[rn]iu|^cu|f[oe]|a[cds]t|has|nob|rad|du

Curium/Cerium are a pain to deal with

qw3n

Posted 2014-01-08T21:31:34.413

Reputation: 733