News for hackers. Stuff that matters.
Re:Regex that only matches itself by mepcotterell on Friday November 11, 2016 @02:59PM (#12933791)
I think I might be missing something. Wouldn't something like "a" be a valid 1-byte regular expression that only matches instances of "a"?
Re:Regex that only matches itself by TheDong on Friday November 11, 2016 @03:33PM (#12934067)
No. "a" produces a match when run on "a" and "bad" and "aaaa" and many more things.

The regex ^a$ only matches "a", but it doesn't match itself.

Re:Regex that only matches itself by taeric on Friday November 11, 2016 @03:38PM (#12934106)
That isn't a match...

I can still see the neat aspect of the post. But that is not a match.

Re:Regex that only matches itself by bertiewhykovich on Friday November 11, 2016 @03:58PM (#12934276)
What do you mean?
Re:Regex that only matches itself by mcpherrinm on Friday November 11, 2016 @04:15PM (#12934400)
Regex libraries often distinguish between a string containing a regex, and matching it.

The string "aaaa" is a Regular Expression that describes a language with exactly one string: "aaaa".

Some regular expression libraries have two operations: They can tell you if a string contains a match somewhere within it, or is exactly a match. Some other libraries only do the first operation, and you need to explicitly ask for "^aaaa$" to get an exact match.

This is one of the things on the differences between the formal definition of a Regular Expression, and a regex library.

Re:Regex that only matches itself by taeric on Friday November 11, 2016 @06:19PM (#12935377)
Yeah. I want trying to be a jerk. Pedantic some, but I thought the difference between match and find was pretty general in regex land.
Re:Regex that only matches itself by idbehold on Friday November 11, 2016 @03:04PM (#12933830)
> NOTE, delimiters must be included

Your regex is actually /a/ which does not match the string "/a/".

Re:Regex that only matches itself by takeda on Friday November 11, 2016 @03:13PM (#12933914)
I would say that adding slashes is quite arbitrary constraint, and it is really language specific syntax that is limited to minority of languages (I believe it was introduced in Perl). If you do regexp in Java, Python, C you don't use slashes.

Edit: looks like slashes weren't even used in the example.

Re:Regex that only matches itself by mcpherrinm on Friday November 11, 2016 @03:15PM (#12933926)
It's a pretty boring question if you don't make that requirement, though. The whole exercise is arbitrary, so it doesn't bother me.
Re:Regex that only matches itself by bazzargh on Saturday November 12, 2016 @06:35AM (#12937482)
Perl's use of this syntax had ancestors in awk, sed, ed, and qed - originally just for string replacements in qed until Ken Thompson wrote a version that did regexps too. It dates back to 1967. https://www.bell-labs.com/usr/dmr/www/qed.html

Deutsch&Lampson's original paper on qed showing s/// used for string substitution prior to it gaining regexps is here: http://research.microsoft.com/en-us/um/people/blampson/04-On...

Incidentally the name 'grep' originated here, 'G/RE/P' was a qed command to do a Global Regular Expression match and Print the matches.

Re:Regex that only matches itself by idbehold on Friday November 11, 2016 @04:09PM (#12934354)
Okay, I'll quote some more from the question:

> […] 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.

Re:Regex that only matches itself by mepcotterell on Friday November 11, 2016 @03:05PM (#12933835)
Ahh. Thank you.