* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Regex golf  (Read 455 times)

0 Members and 1 Guest are viewing this topic.

Offline JWinslow23

  • Should my fans be called "Elephants", "Cookie Clickers", or "Descenders"?
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and 2↑↑↑6
  • Posts: 773
  • Post Rating Ratio: +13/-1
  • 99.999...% of mathematicians agree, tau > pi.
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Regex golf
« on: 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 »


  • Calculators owned: TI-84+, TI-84+ CSE, TI-84+ CE

Offline kotu

  • -< \'V/,,,
  • Super User
  • Join Date: Aug 2016
  • Location: don't panic
  • Posts: 1160
  • Post Rating Ratio: +7/-11
  • woah
    • dj_kotu
    • @UCAy2ZF4hbc08iStnTn6jgxQ
    • rowanmedhurst
    • @romanov-psyco
    • futurerave.uk
  • Gender: Male
Re: Regex golf
« Reply #1 on: July 24, 2017, 03:12:26 pm »
BUSTED - this does not work. You are now busted.
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Offline JWinslow23

  • Should my fans be called "Elephants", "Cookie Clickers", or "Descenders"?
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and 2↑↑↑6
  • Posts: 773
  • Post Rating Ratio: +13/-1
  • 99.999...% of mathematicians agree, tau > pi.
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Re: Regex golf
« Reply #2 on: July 24, 2017, 09:31:11 pm »
BUSTED - this does not work. You are now busted.
What doesn't work? And how? I have tested these with all acceptable inputs.

Offline kotu

  • -< \'V/,,,
  • Super User
  • Join Date: Aug 2016
  • Location: don't panic
  • Posts: 1160
  • Post Rating Ratio: +7/-11
  • woah
    • dj_kotu
    • @UCAy2ZF4hbc08iStnTn6jgxQ
    • rowanmedhurst
    • @romanov-psyco
    • futurerave.uk
  • Gender: Male
Re: Regex golf
« Reply #3 on: July 24, 2017, 09:33:39 pm »
Oh ok. I guess they must work then. I stand corrected.
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Offline _iPhoenix_

  • Super User
  • Join Date: Mar 2017
  • Location:
  • Posts: 539
  • Post Rating Ratio: +12/-1
  • █████ ▼ ♪ Best music ♫
    • @dj_iPhoenix
    • @UCytgMNPxAMDsxjimvxHf01w
    • @the-legend-of-iphoenix
  • Gender: Male
Re: Regex golf
« Reply #4 on: 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.
  • Calculators owned: A sentient TI-84+ CE, TI-85
  • Consoles, mobile devices and vintage computers owned: TI-99/4a home computer
Please spam here: https://legend-of-iphoenix.github.io/spam/

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me

Offline JWinslow23

  • Should my fans be called "Elephants", "Cookie Clickers", or "Descenders"?
  • Super User
  • CW 4x3 challenge - 2nd place
  • *
  • Join Date: May 2015
  • Location: Somewhere between 13 and 2↑↑↑6
  • Posts: 773
  • Post Rating Ratio: +13/-1
  • 99.999...% of mathematicians agree, tau > pi.
    • @UCu_9qD95nADzc-W6RN-3Z8A
    • 113/11328
  • Gender: Male
Re: Regex golf
« Reply #5 on: 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

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games