On 6/26/06, Daniel DeLorme <dan-ml / dan42.com> wrote:
> Logan Capaldo wrote:
> >
> > Regular expressions are a very powerful tool, but they do not describe
> > the entire set of operations one would reasonably want to perform on a
> > string. Or perhaps they do but in a needlessly complex way. I want to
> > get the first letter (character?) of a sentence, in pure regexp terms
> > I'd do this: str.match(/\A./)[0] It's needlessly cryptic. Note that I'm
> > not trying to make a commentary on whether or not character string/byte
> > string should be separate, just trying to point out that "use regular
> > expressions" shouldn't always be the answer.
>
> It's funny, maybe I'm just dumb but I can't think of a single *real-world*
> example where you'd want to access particular characters of a string. Why do you
> want the first char? In the context of a byte string there might be something
> special at position n (e.g. exif header), but in the context of a human-readable
> string what is there? For example, if you want that first char in order to check
> if it's a space or not, you should use str =~ /^ /, etc, etc. I honestly can't
> think of any real-world examples where regular expressions are less appropriate
> than pointer arithmetic. Can you illuminate me with some?

Have you looked at the "short but unique" ruby quiz?

Also when you are building some search trees or such you want access
to letters one by one.

Thanks

Michal