You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

Regex golf

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

0
b/Other publicado por u/JWinslow23 July 21, 2017, 11:45:51 PM
In honor of this xkcd comic, I made these regexes.

/[ckp]e|j| t/
Matches: The subtitles of each Star Wars movie (yes, even "The Force Awakens" and "The Last Jedi")
Doesn't match: The subtitles of each Star Trek movie
Special notes: The Star Trek movie without a subtitle isn't counted, as it does not have a subtitle.

/f?i.?[ns]|h |y/
Matches: The subtitles of each Star Trek movie
Doesn't match: The subtitles of each Star Wars movie
Special notes: The Star Trek movie without a subtitle isn't counted, as it does not have a subtitle.

/[jt]o|[lm][as]|n[ae]|r.e|dr/
Matches: The last names of US Presidents who were Democrats
Doesn't match: The last names of US Presidents who were Republican
Special notes: Franklin Delano Roosevelt is rendered as "fdr".

/g|s[eh]|o[lor]|.[kpx]|^[ht]?a/
Matches: The last names of US Presidents who were Republican
Doesn't match: The last names of US Presidents who were Democrats
Special notes: Franklin Delano Roosevelt is rendered as "fdr".

Can anyone optimize these/make others?
Last Edit: July 22, 2017, 12:14:03 AM by JWinslow23
Inicia sesión o crea una cuenta para dejar un comentario
u/kotu July 24, 2017, 03:12:26 PM
BUSTED - this does not work. You are now busted.
u/JWinslow23 July 24, 2017, 09:31:11 PM
Quote from: kotu on July 24, 2017, 03:12:26 PM
BUSTED - this does not work. You are now busted.
What doesn't work? And how? I have tested these with all acceptable inputs.
u/kotu July 24, 2017, 09:33:39 PM
Oh ok. I guess they must work then. I stand corrected.
u/_iPhoenix_ July 25, 2017, 08:50:00 PM
I have a few, will be posting in a week when I get home (on vacation :/)

I have a few challenges.
I am looking for RegEx statements that...
-accept the names of the top 5 renewable energy sources, but reject the top 5 non-renewable ones
-accept the capital cities of US states, but reject the names of the states (i.e. "Columbus" would pass, but "Ohio" would not)

I'll post more challenges as I think of 'em.
u/JWinslow23 July 31, 2017, 12:16:37 AM
Top 5 renewable energy sources:
Hydropower, Biomass Wood, Biomass Waste, Biomass Biofuel, Wind
Top 5 non-renewable energy sources:
Coal, Petroleum, Natural Gas, Nuclear Energy, Fossil Fuels

Match non-renewable but not renewable:
/c|[ms]$/

Match renewable but not non-renewable:
/b|w/

And here's a badly-done regex golf of the states/capitals problem.

Match states but not their capitals:
/[aio].a.{0,3}$|^[gku-w]|^m[ai][^d]|^[npt][e]|^[or]\
|i(cu|fo|no)/[/tt]

Match capitals but not their states:
TBD
Last Edit: July 31, 2017, 01:21:03 AM by JWinslow23
Start a Discussion

b/Other

Any discussion that doesn't fit in other categories go here. Also, don't forget to introduce yourself. :)

232
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal