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 0082.

 

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

 

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:

 

 

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'.

 

 

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.

 

 

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

 

 

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

 

Warning!

 

Making global replacements can be very dangerous, and can seriously damage your directory. Make sure you know what changes you are making, and be especially careful with naming attributes. Remember to use the 'Test' button to trial complex changes first, consider using 'prompt' to review every change on production systems. Be aware of possible side effects of changing attributes, such as secondary systems that may be relying on the data being changed, and remember that the effects of changes on multi-valued attributes may be non-obvious.

 

Replace Examples

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

 

 

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.

 

 

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)

 

 

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.

 

 

A successful replace operation will show the before and after text. (It is good practive to always test replacements before executing them!) 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.

 

Multi Valued Attributes

 

Be careful using multivalued attributes as replacement terms. When JXWorkBench is inserting an attribute value (e.g. <$uid>) it will only insert the first value of a multi-valued attribute.

Regular Expression Reference

 

The Regular experessions used are standard java regular expressions. The following is a partial reference only (taken from the java documentation)

╩
Characters
x           The character x
\\          The backslash character
\0n         The character with octal value 0n (0╩<=╩n╩<=╩7)
\0nn        The character with octal value 0nn (0╩<=╩n╩<=╩7)
\0mnn       The character with octal value 0mnn (0╩<=╩m╩<=╩3, 0╩<=╩n╩<=╩7)
\xhh        The character with hexadecimal╩value╩0xhh
\uhhhh      The character with hexadecimal╩value╩0xhhhh
\t          The tab character ('\u0009')
\n          The newline (line feed) character ('\u000A')
\r          The carriage-return character ('\u000D')
\f          The form-feed character ('\u000C')
\a          The alert (bell) character ('\u0007')
\e          The escape character ('\u001B')
\cx         The control character corresponding to x
╩
Character classes
[abc]       a, b, or c (simple class)
[^abc]      Any character except a, b, or c (negation)
[a-zA-Z]    a through z or A through Z, inclusive (range)
[a-d[m-p]]  a through d, or m through p: [a-dm-p] (union)
╩
Predefined character classes
.           Any character (may or may not match line terminators)
\d          A digit: [0-9]
\D          A non-digit: [^0-9]
\s          A whitespace character: [ \t\n\x0B\f\r]
\S          A non-whitespace character: [^\s]
\w          A word character: [a-zA-Z_0-9]
\W          A non-word character: [^\w]
╩
╩
Boundary matchers
^           The beginning of a line
$           The end of a line
\b          A word boundary
\B          A non-word boundary
\A          The beginning of the input
\G          The end of the previous match
\Z          The end of the input but for the final terminator, if╩any
\z          The end of the input
╩
Greedy quantifiers
X?          X, once or not at all
X*          X, zero or more times
X+          X, one or more times
X{n}        X, exactly n times
X{n,}       X, at least n times
X{n,m}      X, at least n but not more than m times
╩
Reluctant quantifiers
X??         X, once or not at all
X*?         X, zero or more times
X+?         X, one or more times
X{n}?       X, exactly n times
X{n,}?      X, at least n times
X{n,m}?     X, at least n but not more than m times
╩
Possessive quantifiers
X?+         X, once or not at all
X*+         X, zero or more times
X++         X, one or more times
X{n}+       X, exactly n times
X{n,}+      X, at least n times
X{n,m}+     X, at least n but not more than m times
╩
Logical operators
XY          X followed by Y
X|Y         Either X or Y
(X)         X, as a capturing group
╩
Back references
\n          Whatever the nth capturing group matched╩

Quotation
\           Nothing, but quotes the following character
\Q          Nothing, but quotes all characters until \E
\E          Nothing, but ends quoting started by \Q
 ╩
Special constructs (non-capturing)
(?:X)       X, as a non-capturing group
(?=X)       X, via zero-width positive lookahead
(?!X)       X, via zero-width negative lookahead
(?<=X)      X, via zero-width positive lookbehind
(?X)       X, as an independent, non-capturing group