« Using the Advanced Filter | Main | Rough Draft: Video Tutorial of Creating a Database and Simple Mail Merge »

November 26, 2007

Using regular expressions in OpenOffice Calc filters -- phrases like "contains" rather than equals, less than, etc.

Regexlogo_3

Life just isn't cut and dried. Sometimes when you're filtering you don't want to just say "give me all the people whose last name is Hanson." You want Hanson, Hansen, and Hansengaaardennn (those Dutch really go for the jawbreaker names).

You'd like to filter out everyone except those whose names contain "Hans".

Here's how to do that. Select the item in the Comparison Field from the dropdown list in the standard filter, then type what you want in the other field. Click More, and select Regular Expressions, then click OK.

Example of what you want

What to enter in the Condition field

Syntax for what to enter in the Value field

Example of what to enter in the Value field

Begins with Hans

=

^x.*

^Hans.* (you can also skip the ^, I've found)

Does not begin with Hans

<>

^x.*

^Hans.*

Ends with Hans

=

.*x$

.*Hans$

Contains Hans

=

.*x.*

.*Hans.*

Does not contain Hans

<>

.*x.*

.*Hans.*

Here are some examples. Let's say you want all names that start with Hans, but not all names that simply contain Hans.

Here's the data.
Startswith1

Select all  the data, or just click in the headings, and choose Data > Filter > Standard Filter. Make the window look like this.
Startswith2

Click OK and you get this; Bob Montrahans is not included. (It's not because of the case.)
Startswith3

Here's a different example. I want names that DON'T CONTAIN the series of letters Hans.

Data
Contains1

The window with the restrictions:

Contains2

And the results.

Contains3

Here's some information from the OOo wiki about regular expressions.



Traininglogo




TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/551685/23383394

Listed below are links to weblogs that reference Using regular expressions in OpenOffice Calc filters -- phrases like "contains" rather than equals, less than, etc.:

Comments

Post a comment