Softerra LDAP Administrator HelpShow AllHide All

Regular Expressions for Find and Replace

Regular expressions are a concise and flexible notation for finding and replacing patterns of text. A specific set of regular expressions can be used in the Find what field of the LDAP Administrator Find and Replace Window.

Regular expressions that can be used in the Find What field

ExpressionSyntaxDescription
Any character . Matches any single character except a line break.
Zero or more * Matches zero or more occurrences of the preceding expression, making all possible matches.
Zero or more (lazy) *? Lazy version of the * quantifier. Matches the minimal occurrences of the preceding expression.
One or more + Matches at least one occurrence of the preceding expression.
One or more (lazy) +? Lazy version of the + quantifier. Matches the minimal occurrences of the preceding expression.
Zero or one ? Matches zero ore one occurrence of the preceding expression.
Zero or one (lazy) ?? Lazy version of the ? quantifier. Matches the minimal occurrences of the preceding expression.
Beginning of line ^ Anchors the match string to the beginning of a line.
End of line $ Anchors the match string to the end of a line.
Any one character in the set [] Matches any one of the characters within the []. To specify a range of characters, list the starting and ending character separated by a dash (-), as in [a-z].
Any one character not in the set [^...] Matches any character not in the set of characters following the ^.
Or | Matches either the expression before or the one after the OR symbol (|). Mostly used within a group. For example, (sponge|mud) bath matches "sponge bath" and "mud bath."
Prevent match !(X) Prevents a match when X appears at this point in the expression. For example, real!(ity) matches the "real" in "realty" and "really," but not the "real" in "reality."
Escape \ Matches the character that follows the backslash (\) as a literal. This allows you to find the characters used in regular expression notation, such as { and ^. For example, \^ Searches for the ^ character.
Tagged expression {} Matches text tagged with the enclosed expression.
Grouping () Groups a subexpression.
Alphanumeric character \a Matches the expression ([a-zA-Z0-9]).
Space or Tab \b Matches either space or tab characters.
Alphabetic character \c Matches the expression ([a-zA-Z]).
Decimal digit \d Matches the expression ([0-9]).
Hexadecimal digit \h Matches the expression ([0-9a-fA-F]).
Quoted string \q Matches the expression (\"[^\"]*\")|(\'[^\']*\').
Alphabetic string \w Matches the expression ([a-zA-Z]+).
Integer \z Matches the expression ([0-9]+).
Previous match \index Matches the same that matched tagged expression by index. For example, {\w}\0 finds doubled word characters.

Substitutions that can be used in the Replace With field.

ExpressionSyntaxDescription
Substitution \index Indicates a substitute of a tagged expression by index. '\0' indicates the text matched by the whole regular expression pattern.
New line \n Indicates a substitute of a new line character.
Back slash \\ Indicates a substitute of the '\' character.

Example of using regular expressions

Find What: ^{[^ ]+} {\d+ \d+} *$
Replace With: dn: cn=\1,ou=ou,o=company\nchangetype: modify\nreplace: telephoneNumber\ntelephoneNumber: \2\n

Text

Person1 123 2344
Person2 555 5555

Will be transformed into:

dn: cn=Person1,ou=ou,o=company
changetype: modify
replace: telephoneNumber
telephoneNumber: 123 2344

dn: cn=Person2,ou=ou,o=company
changetype: modify
replace: telephoneNumber
telephoneNumber: 555 5555
            

See Also