- 559
- 1
- 4
- 11
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
- 2.5k
- 3
- 18
- 26