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

See updated code above using fancier pattern. (Why do you think think the original would not work for alpha?)
  • Comment on Re^3: match whitespace or beginning/end of string

Replies are listed 'Best First'.
Re^4: match whitespace or beginning/end of string
by azadian (Sexton) on Oct 30, 2009 at 14:04 UTC
    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
        My guess is that anything more complicated than \b is going to be too much to ask of my users. \b and \s do not work if the substring is at the beginning of the string. The more complicated it is, they less likely they are to use my wonderful tool.