Joker -- Wildcards for Ruby

Hi folks,
I’m proudly presenting:

Joker

http://karottenreibe.github.com/joker

Joker is a Wildcard implementation for Ruby.

Features

  • Behaves much like Regexp
  • * and ? as wildcard characters
  • \ for escaping
  • \a matches \a, but not a
  • Wildcards must always match whole string
  • Wildcards can be case insensitive

Visit the website to see a small example etc.

Greetz!

On Sep 9, 2009, at 12:55 PM, Fabian S. wrote:

  • Behaves much like Regexp
  • * and ? as wildcard characters
  • \ for escaping
  • \a matches \a, but not a
  • Wildcards must always match whole string
  • Wildcards can be case insensitive

Can you suggest why someone would use this instead of a regular
expression?

James Edward G. II

because “non-computer people” (:slight_smile: might find wildcards more easily
understandable than regular expressions.

This is of course not meant as a replacement for regexps when you’re
writing code but rather as a way to interface with people who don’t
know about regexps

think directory listings, search queries etc.

Greetz!

2009/9/9 James Edward G. II [email protected]

At 2009-09-09 01:55PM, “Fabian S.” wrote:

[Note: parts of this message were removed to make it a legal post.]

Hi folks,
I’m proudly presenting:

Joker

http://karottenreibe.github.com/joker

Joker is a Wildcard implementation for Ruby.

Note that these are known as “glob patterns” – you might want to update
your documentation accordingly
(glob (programming) - Wikipedia)

Also, your rdocs seem to be missing a few backslashes:

* '?' matches a single character
* '*' matches any number of characters, including 0

(1) * ‘’ matches a literal '
* ‘?’ matches a literal ‘?’
(2) * '' matches a literal ''

1 should be: ‘*’ matches a literal ‘*’
2 should be: ‘\’ matches a literal ''

You could generalize by saying:
* ‘\x’ matches the literal character ‘x’, even if ‘x’ is a wildcard
character.

You haven’t implemented bracket expressions: ‘[cb]at*’ should match
‘catch’ and ‘batch’ but not ‘match’

Tcl has had this functionality for years, and it’s very handy to be able
to do a quick glob comparison on a string when you don’t need the full
power of a regular expression.
(string manual page - Tcl Built-In Commands)

Whoops overlooked one:

You could generalize by saying:

  • ‘\x’ matches the literal character ‘x’, even if ‘x’ is a wildcard
    character.

That’s exactly not what my implementation does. Since I had the library
in
mind as
a way to interact with users who don’t know about Regular Expressions, I
wanted
to keep it as simple as possible.

Thus, the Ruby String “fo\o” fed to the Wildcard class would be
equivalent
to /^fo\o$/
but I’m not sure if that was a wise decision. The reasoning behind it
was,
that users woudn’t
have to type things like
C:\foo\bar\goo
but rather only
C:\foo\bar\goo
since f b and g are no special characters.

Does that make sense? What do you think? Which approach to take or
should
there be an option
and if so what’s the wiser default?
Greetz!

Note that these are known as “glob patterns” – you might want to update
your documentation accordingly (glob (programming) - Wikipedia)

Ah, thx, I’ve been searching for the correct name of these but couldn’t
find
it.
The only thing I’ve ever heard was “Wildcard”.

2 should be: ‘\’ matches a literal ''

You could generalize by saying:

  • ‘\x’ matches the literal character ‘x’, even if ‘x’ is a wildcard
    character.

I’ll do that.

You haven’t implemented bracket expressions: ‘[cb]at*’ should match
‘catch’ and ‘batch’ but not ‘match’

I’ll look into that.

Thanks for the feedback!

Just a thought… ruby already has globbing functions in dir.c, but they
apparently work only on dirs. Maybe they could be abstracted in to a
library that works on strings or arrays of strings.

Just a thought… ruby already has globbing functions in dir.c, but they
apparently work only on dirs. Maybe they could be abstracted in to a library
that works on strings or arrays of strings.

Honestly: I have no idea what’s going on in that file…
That’s just too complicated C magic whuzzing around in there.

But a problem with that approach – as far as I can tell – is that
matching a glob against a string and matching it against the
file system are 2 different things. Especially since “/” or “” have
special meaning in file systems and allow for splitting of the glob
string into small subsections, whose matching against files is much
easier.
Also dir.c has the special “**” glob, which doesn’t make and sense
in string matching.

Greetz!