On September 21, 2007, Mark Phillips wrote: > I am using Dcount() to count the occurrences of some strings in a > spreadsheet in OpenOffice Calc 2.0.3. I am using a regular expression to > find the string I want. My regular expression is > > \[['a-zA-Z', ]*'Board Member'(, )?['a-zA-Z']*(, )?\]|Board Member > > It works for all of these test cases: > ['Volunteer', 'Board Member', 'Coach'] > Board Member > ['Volunteer', 'Manager', 'Board Member'] > > but not this one: > ['Board Member', 'Volunteer', 'Coach'] > > I had thought this part of the regular expression ['a-zA-Z', ]* would take > care of this case with the "zero" part of the definition of the "*". But it > doesn't. Do I need to add another "or" term for this case, or is there a > way to modify my regular expression to handle this case. > > BTW, I tried using [:alpha:] instead of [a-zA-Z], and dcount() did not find > any matches. Is [:alpha:] not working - it is listed in the documentation > as a valid regular expression. > > Thanks!
\[['a-zA-Z', ]*'Board Member'(, )?['a-zA-Z']*(, )?\]|Board Member I think the problem is that the first * finds 'Board Member' in the case where 'Board Member' comes first, then the expression is looking for another 'Board Member', then zero or one comma+space, then whatever remaining. This would find ['Board Member','Board Member',....] How about \[(['a-zA-Z', ]*)?'Board Member'(, )?(['a-zA-Z']*)?(, )?\]|Board Member If I'm not mistaken, either of these regular expressions will fail if it receives input where there is a comma after 'Board Member' but not a space following the comma. ie ['Volunteer','Board Member','Coach'] If that could happen you may want \[(['a-zA-Z', ]*)?'Board Member'(, |,)?(['a-zA-Z']*)?(, |,)?\]|Board I haven't tested any of this, but that's how it seems to me at first look. (and I'm already going cross-eyed looking at it!) Cheers, IanS --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
