Main | What is Trackback? »

What is a Regex Search?

If you have installed the basic MT package and are including the default search function on your blog, you may have noticed a check box for "Regex Search" that appears underneath the search box on your search results page. There is also a check box for "Match Case", but that is more self-explanatory. What is a "Regex" search? And how can you get rid of that check box so you don't confuse your visitors?

search this site

What is a Regex search?

Regex stands for "Regular Expression". It is a programming term. Doing a Google search reveals several definitions:

Regular Expression is a sentence written in a language to describe patterns.

or

A regular expression is a way of describing a group of words (referred to as a 'string'). It allows a user to build a complex set of rules to describe exactly what characteristics the string should have. While this documentation uses the word string you can think of a string as either a filename when searching for a filename using regular expressions, or as text in a document when using a regular expression to search the contents of files.Source.

The best description I've found so far is

Regular expression is a way to specify conditions to be fulfilled for a situation in mind. Normally when you search in a text editor you specify the text to search for literally, using regular expression, on the other hand, you tell what a given match would look like. Examples of this includes I'm searching for the word KDE, but only at the beginning of the line, or I'm searching for the word the, but it must stand on its own, or I'm searching for files starting with the word test, followed by a number of digits, for example test12, test107 and test007 docs.kde.org

Basically, a regex search lets you add code on either side of your search term to be more specific about how you want that search to take place. On my recipe site, if I wanted to search for "apple" but not "applebutter", I would type \bapple\b into the search field with the regex box checked.

This function is very useful for programming types who 1) know what a regular expression is and 2) know how to use regular expressions to conduct searches. But for the rest of us, it is just confusing. 99 percent of the visitors who come to my recipe site and conduct a search have no idea what a regex search is. So I got rid of the check box on the search results page of that site.

How to Get Rid of the Regex Search Check Box

To remove the Regex search box you need to edit the search template* you are using for your weblog. If you have multiple weblogs and you only want to adjust the search template for one or some of your blogs, you will need to create an alternate search template for those blogs. Directions on how to create an alternate search template can be found here in the tutorial MT Keyword Search.

Whether you create a new alternate template or use the default template, to remove the check box you will need to edit line #27 from the search template. The line reads:

<input type="checkbox" name="CaseSearch" /> Match case <input type="checkbox" name="RegexSearch" /> Regex search<br/><br />

Either remove the entire line, in which case you remove the check box for "Match case" as well, or remove only the tags having to do with Regex search. Save the file. Rebuild your site. The check boxes should now be missing from your search result pages.

*Your search templates can be found in a directory named "search_templates" with your other Movable Type files on your server. In my case, this directory is in the cgi-bin.

Links:

Regular Expressions Tutorial
MT Keyword Search LMT tutorial