Regex in Koha

Regex

A regular expression (shortened as Regex or Regexp) is a sequence of characters that specifies a search pattern. Usually, such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.

In Koha, with Regex, a replacement can be inserted into a Koha item field. This will be helpful when you want to alter a field but not completely remove the rest of the contents.

Batch Item Modification

In Batch Item Modification (found in the Tools module), Koha has the ability to use Regex to alter the contents of many item fields.


Not all fields will have the Regex option available. For example, fields that are connected to an authorized value (such as Item type, Shelving location, Collection code) cannot use Regex.

Monday Minutes: Using Regex in Batch Item Modification


Examples

The two examples discussed in the tutorial video involve adding further text to an already-used note field.
  1. Example 1: If a library had a public/nonpublic note attached to items, but wanted to add more text, using Regex would allow adding the new text to either the beginning of the field or at the end of the already-existing text.
    1. To add the text to the end of the already existing text, click the 'Regex' option next to that specific field, then in the s/ text box, add a $. In the next box, / you will add the text.
  2. Example 2: Replacing the $ with the ^ - which would put the new text in front of the already existing text.
Another great way to use Regex in Batch Item Modification is to only replace a section of the already-existing text. For example, if a library used their 'Materials Specified'/952$3 field to tell a staff member to "take the item to Carol" - but now needed it to say "take the item to Barbara", they could use Regex to find the word "Carol" and replace it with "Barbara".