in reply to Re: match whitespace or beginning/end of string
in thread match whitespace or beginning/end of string

Works fine for beta, but the same code would not work for alpha. The point is, I don't know the location in the string of the word I'm matching. You're right that, in this case, I don't need to worry about the end of string. But still, I'd like to be able to give my users a general-purpose rule which works even without the quotes.
  • Comment on Re^2: match whitespace or beginning/end of string

Replies are listed 'Best First'.
Re^3: match whitespace or beginning/end of string
by gmargo (Hermit) on Oct 30, 2009 at 13:19 UTC
    See updated code above using fancier pattern. (Why do you think think the original would not work for alpha?)
      Yes, the improved code is fine, and covers all cases. However, the goal is to have code which is fine and covers all cases AND IS SIMPLER. I want simple because I need to recommend this to testers who don't know necessarily know what a regular expression is. I can tell them to stick in a \b at the beginning and end of each word to be matched, and I can even explain it to them. Unfortunately, \b doesn't always work. The more complicated expressions such as you used (and I suggested) are not so easy to recommend or explain. I just want to know if there is some simple way to do what seems like a simple task.

        I, for one, always prefer "simple" (or "simpler"). But, it seems to me, that "simpler" is not always compatible with the demands of the situation.

        It seems to me (not that I'm by any means really qualified to make this assertion) that the situation you're addressing is, by its nature, not easily handled by anything "simple". In my experience this is espeically true (or perhaps I should say "tends to be true"...I guess it depends upon one's familiarity and accumen with regexs) when regexs are involved.

        I think the strategy that gmargo proposed is elegantly "simple" in terms of regexs and I, like gmargo, am not sure why it wouldn't work for cases other than just for 'beta'.

        At the end of the day, I guess I don't know what you're imagining is "simple" or "simpler". But that's probably just my misunderstanding of what you're looking for.

        ack Albuquerque, NM