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 Question

Question Unprotected by caird coinheringaahing
Question Protected by Community Bot
Notice removed Reward existing answer by MD XF
Bounty Ended with jimmy23013's answer chosen by MD XF
Notice added Reward existing answer by MD XF
Bounty Started worth 100 reputation by MD XF
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

There are some pretty cool challenges out there involving regex (Self-matching regex Self-matching regex, Regex validating regex Regex validating regex)

This may well be impossible, but is there a regex that will ONLY match itself?

NOTE, delimiters must be included:

for example /thing/ must match /thing/ and not thing. The only match possible for your expression must be the expression itself. Many languages allow the implementation of a string in the place of a regular expression. For instance in Go

package main
import "fmt"
import "regexp"
func main() {
 var foo = regexp.MustCompile("bar")
 fmt.Println(foo.MatchString("foobar"))
}

but for the sake of the challenge, let the expression be delimited (starting symbol, expression, ending symbol ex: /fancypantpattern/ or @[^2048]@), if you want to argue quotes as your delimiter, so be it. I think given the apparent difficulty of this problem it won't make much of a difference.

To help you along:

Quick hack I put together for rubular.com (a webpage for ruby regex editing):

var test = document.getElementById("test")
,regex = document.getElementById("regex")
,delimiter="/"
,options = document.getElementById("options")
,delay = function(){test.value = delimiter + regex.value + delimiter + options.value}
,update = function(e){
 // without delay value = not updated value
 window.setTimeout(delay,0);
}
regex.onkeydown = update;
options.onkeydown = update;

Even though this is technically 'code golf' I will be very impressed if anyone can find an answer/ prove it is impossible.

Link is now fixed. Sorry to all

Winning answer thus far: jimmy23013 with 40 characters

There are some pretty cool challenges out there involving regex (Self-matching regex, Regex validating regex)

This may well be impossible, but is there a regex that will ONLY match itself?

NOTE, delimiters must be included:

for example /thing/ must match /thing/ and not thing. The only match possible for your expression must be the expression itself. Many languages allow the implementation of a string in the place of a regular expression. For instance in Go

package main
import "fmt"
import "regexp"
func main() {
 var foo = regexp.MustCompile("bar")
 fmt.Println(foo.MatchString("foobar"))
}

but for the sake of the challenge, let the expression be delimited (starting symbol, expression, ending symbol ex: /fancypantpattern/ or @[^2048]@), if you want to argue quotes as your delimiter, so be it. I think given the apparent difficulty of this problem it won't make much of a difference.

To help you along:

Quick hack I put together for rubular.com (a webpage for ruby regex editing):

var test = document.getElementById("test")
,regex = document.getElementById("regex")
,delimiter="/"
,options = document.getElementById("options")
,delay = function(){test.value = delimiter + regex.value + delimiter + options.value}
,update = function(e){
 // without delay value = not updated value
 window.setTimeout(delay,0);
}
regex.onkeydown = update;
options.onkeydown = update;

Even though this is technically 'code golf' I will be very impressed if anyone can find an answer/ prove it is impossible.

Link is now fixed. Sorry to all

Winning answer thus far: jimmy23013 with 40 characters

There are some pretty cool challenges out there involving regex (Self-matching regex, Regex validating regex)

This may well be impossible, but is there a regex that will ONLY match itself?

NOTE, delimiters must be included:

for example /thing/ must match /thing/ and not thing. The only match possible for your expression must be the expression itself. Many languages allow the implementation of a string in the place of a regular expression. For instance in Go

package main
import "fmt"
import "regexp"
func main() {
 var foo = regexp.MustCompile("bar")
 fmt.Println(foo.MatchString("foobar"))
}

but for the sake of the challenge, let the expression be delimited (starting symbol, expression, ending symbol ex: /fancypantpattern/ or @[^2048]@), if you want to argue quotes as your delimiter, so be it. I think given the apparent difficulty of this problem it won't make much of a difference.

To help you along:

Quick hack I put together for rubular.com (a webpage for ruby regex editing):

var test = document.getElementById("test")
,regex = document.getElementById("regex")
,delimiter="/"
,options = document.getElementById("options")
,delay = function(){test.value = delimiter + regex.value + delimiter + options.value}
,update = function(e){
 // without delay value = not updated value
 window.setTimeout(delay,0);
}
regex.onkeydown = update;
options.onkeydown = update;

Even though this is technically 'code golf' I will be very impressed if anyone can find an answer/ prove it is impossible.

Link is now fixed. Sorry to all

Winning answer thus far: jimmy23013 with 40 characters

edited tags
Link
user45941
user45941
Loading
Question Unprotected by DJMcMayhem
update winning answer length
Source Link
DJMcMayhem
  • 60.1k
  • 18
  • 203
  • 352
Loading
Loading
Notice removed Reward existing answer by NoOneIsHere
Bounty Ended with jimmy23013's answer chosen by NoOneIsHere
Notice added Reward existing answer by NoOneIsHere
Bounty Started worth 50 reputation by NoOneIsHere
Notice removed Reward existing answer by Dennis
Bounty Ended with jimmy23013's answer chosen by Dennis
Notice added Reward existing answer by Dennis
Bounty Started worth 500 reputation by Dennis
Question Protected by Community Bot
edited tags
Link
user16402
user16402
Loading
Update winning answer
Source Link
Dylan Madisetti
  • 3.8k
  • 3
  • 16
  • 13
Loading
We have a Winner!
Source Link
Dylan Madisetti
  • 3.8k
  • 3
  • 16
  • 13
Loading
1
2

AltStyle によって変換されたページ (->オリジナル) /