Live data from Hacker News

Regex Golf

regex.alf.nu

131–140 of 189 posts

Re: Regex Golf

#132
post #123
post #113

Earlier quoted context omitted.

Prime: ^x{2,3}$|^x{5}$|^x{7}$|^x{11}$|^x{13}$|^x{17}$|^x{19}$|^x{23}$|^x{29}$|^x{31}$|x{33}

josephlord's solution is much nicer: ^(?!(..+)(\1)+$)

Look at the parent.

Re: Regex Golf

#133

Earlier quoted context omitted.

Just to follow my thought pattern. I start with (.)(.)\2\1 Now to invert I change it to (?!(.)(.)\3\2) As you say, the negation matches an empty string. So I put on anchors: ^(?!(.)(.)\3\2)$ But now it matches nothing. I'm not even sure what that regexp says. The entire string is a negation? Would anything match that regexp? I see elsewhere on this page that the answer involves putting in an extra dummy character, pu…

^(?!.*(.)(.)\2\1) You may also need to fill in the places where it could be anything. The above worked on abba for me. BTW a double space indent then formats as code on HN I think.

Your approach scores higher, but it only matches the (imaginary) space before the "good" words.

I went with:

^(?!.(.)(.)\2\1).$

with the thought that if I really wanted those matches I would want the whole strings.

Fun game!

Re: Regex Golf

#134
post #101

Glob (333) without cheating (replace ⁕s with asterisks, they get turned into italics): ^(\⁕?)(\w⁕)(\⁕?)(\w⁕)(\⁕?)(\w⁕) .⁕ ((.(?!\1))+|\1)\2((.(?!\3))+|\3)\4((.(?!\5))+|\5)\6$ Edit: ((.(?!\1))+|\1) is used to conditionally match .+ iff a * has been found. .(?!\1) Matches any character if it is followed by \1. When * has been found then it matches no character, when * is not found it matches every character. Edit 2: Fo…

  le[^*]|co|ito|dr|^p|su|gi|nr|hw|fa|[eo]b|ide
Glob 376 although it isn't pretty and better may be possible.

Indent two spaces with a blank line above to avoid code mangling.

Re: Regex Golf

#135

Does anybody know how to do math with regex? (triples) And conditionals don't seem to work?

My guess is that 147 must appear the same number of times as 258, but I'm not sure if that's even expressible in regexp.

Refined: [0369] can appear any number of times [147] and [258] must appear an equal number of times, or for any remaining: [147] must appear a multiple of 3 times [258] must appear a multiple of 3 times

Re: Regex Golf

#136
For Abba...

Why doesn't (.)(.)\2[^\1] work?

I thought backreferences matched the captured literal, so negating it would match? But this looks the same as (.)(.)\2\1...

Re: Regex Golf

#137
post #50

Earlier quoted context omitted.

Therefore, the score it provides should be a running tally of how many characters you've used to make it match the scoring system of golf; which is the lowest number of strokes wins. The scoring system for this is incremental which is the opposite of golf. A proper scoring system with this would provide a character limit (par) for each section and the goal would be to write a shorter regex formula to complete the tas…

I don't get what this is all about. The title was (most probably) derived from Code Golf, which is a competition in coding something with as few characers as possible. Code Golf was derived from Golf, where you want to use as few turns as possible. The score going up and not down, which is done because you get more points the more objectives you fulfill, does not change the objective of this game or what it is based…

From my quick read, Code Golf uses a similar scoring system as to the sport of golf, the lower the score the better.

This game is the opposite, meaning the higher the score the better.

This has nothing to do with the objectives of the games in question, just the scoring method.

To make the sport of golf have a similar scoring system as this game you would grant ten points for every stroke under par, deduct ten points for every stroke over par, and deduct one point for every penalty stroke.

Re: Regex Golf

#139

For Abba... Why doesn't (.)(.)\2[^\1] work? I thought backreferences matched the captured literal, so negating it would match? But this looks the same as (.)(.)\2\1...

You cannot negate a capture, only a character literal. A capture might only be a character but it is NOT a literal,
Post reply on HN