JXWorkBench Find and Replace

Standard Ldap search filters are evaluated on the server; this generally means thay are fast and can be done across the whole directory. However, the search filter syntax is not very flexible, and not all directories support advanced searches, while others will support them only if specific indexes are set.

Using JXWorkBench we can do slower, but more powerful, searches on the client. We can search for keywords even in un-indexed directories, or we can use the power of regular experessions to search for complex patterns.

In addition, we can peform search and replace operations, changing attributes across an entire directory. For additional power regular expressions can be used to capture values in the original text and use those values in the replacement text. For example a phone number attribute could have an international prefix added to all instances, turning "9343 0174" to "(+61) 9343 0174" and "9343 0882" to "(+61) 9343 0882.

There are a number of options to allow more detailed targeting of a search and replace operation:

  • Search Filter: allows you to narrow the search according to a pre-defined search filter (set up in the Search Dialog.
  • Method: 'Prompt' asks you before replacing anything / 'Replace all' automatically makes the changes.
  • Scope: 'Full Tree' searches the entire directory / 'Sub Tree' searches from the currently selected node
  • Matching: 'Plain Text' searches just the text string / 'Use Reg Exp' evaluates both find and replace strings as regular expressions, and allows you to use captured find terms in the replacement text.

Attribute Substitution

As well as using plain text and regular expressions in find and replace operations, you can also use values from other attributes. For example, you could replace a description field with:

'name: <$cn> address: <$address>'

and have each description attribute updated with the name and address of the user.

Find Examples

The following show some simple examples of using find:

Plain Search

Normal text searches can be performed similarly to a search in a word processor. This searches for all description fields that contain the string 'puppy'.

Search with Substitutions

The values of other attributes can be substituted in (although this is rarely useful). This search returns all entries where the description attribute is the same as the uid attribute.

Search with RegExp

Java regular expressions are also supported. This search matches all descriptions with text that contains any of 'puppy', 'kitten' or 'frog'.

Search Results

A successful find operation should show highlighted text, along with clickable links to take you to the corresponding entry. This results page shows the entries found from the 'regular expression' search above, that was looking for any of ''puppy', 'kitten' or 'frog'.

Find and Replace

The following show some simple examples of using find and replace:

Simple Text Replacement

Normal text replacement can be performed similarly to a 'find and replace' in a word processor. This changes all descriptions containg the word 'puppy' to have 'kitten' instead.

img src="img/img/

Attribute Text Replacement

The values of other attributes can be substituted in; if there is no value for a particular entry it will be left blank. This example adds an '(owned by...)' phrase after all occurences of 'puppy' in the description text, and relies on entries having either an ou or a uid value to work. (If an entry had both, both would appear in the text)

RegExp Replacement

Java regular expressions are also supported, including using capturing groups from the 'find' term in the 'replace' text. This shows combining the attribute replacement above with a regexp capturing group that looks for puppy, kitten or frog.

Output Example

A successful replace operation will show the before and after text. (It is good practice to always use the "test" option before executing a replacement!) This example shows the result of the regexp replace above, where we have found all 'puppy', 'kitten' or 'frog' owners, and appended their ou or uid attribute values.