Using Regular Expressions in Search Replace  
Sequence Diagram Editor  Top  Previous  Next

Sequence Diagram Editor supports the use of regular expressions in the search and replace patterns. The Use Regular Expressions checkbox must be checked in order for regular expression patterns to be recognized.  
 
This topic describes the syntax used for regular expressions, which is compatible with the Perl5 regular expression language.  
 
Character Classes  
Character classes represent common sets of related characters. It will match if any one of the characters included in the set matches.  
 
.
Matches any character except newline
[abcdef]
Matches any single character included in the specified set of characters
[^abcdef]
Matches any single character not in the specified set of characters
[0-9a-fA-F]
Use of a hyphen (–) allows specification of contiguous character ranges
\w
Matches any word character
\W
Matches any non-word character
\s
Matches any white-space character (including tabs and newlines)
\S
Matches any non-white-space character
\d
Matches any decimal digit
\D
Matches any non-digit
 
 
Quantifiers  
Both greedy and lazy quantifiers are supported.  
*
Matches zero or more occurrences (e.g., \w* or .*)
+
Matches one or more occurrences(e.g., \w+ or .+)
?
Matches zero or one occurrences (e.g., \w?)
{n}
Matches exactly n occurrences
{n,}
Matches at least n occurrences
{n,m}
Matches any number of occurrences between n and m
*?
Lazy match that consumes as few occurrences as possible (preferably zero)
+?
Lazy match that consumes as few occurrences as possible (at least one is always consumed)
??
Lazy match that consumes zero occurrences if possible, or one otherwise
{n}?
Equivalent to {n}
{n,}?
Lazy match consuming as few occurrences as possible, but at least n
{n,m}?
Lazy match consuming as few occurrences as possible between n and m
 
 
Assertions  
Assertions do not consume characters in the match string but instead cause the match to succeed or fail based on whether or not the assertion expression matches at the current position in the match string.  
^
Match must occur at the beginning of the current line
$
Match must occur at the end of the current line
\A
Match must occur at the beginning of the matching text
\Z
Match must occur at the end of the matching text or before a newline at the end of the matching text
\z
Match must occur at the end of the matching text
\b
Match must occur on a word boundary between \w (word) and \W (non-word) characters
\B
Match must not occur on a word (\b) boundary
(?= exp)
Creates a positive lookahead assertion. In order for the entire input string to be considered a match, the subexpression must match at the current position in the input string
(?! exp)
Creates a negative lookahead assertion. In order for the entire input string to be considered a match, the subexpression must not match at the current position in the input string
(?<= exp)
Creates a positive lookbehind assertion. In order for the input string to be considered a match, the subexpression must match the text immediately preceding the current position in the input string
(?<! exp)
Creates a negative lookbehind assertion. In order for the input string to be considered a match, the subexpression must not match the text immediately preceding the current position in the input string
 
 
Grouping  
Grouping constructs are used to specify precedence and create subexpressions that can be captured for later use during matching or replacement.  
(exp)
Creates an unnamed subexpression that captures the matching substring. Unnamed capture groups are numbered automatically starting from one in the order of opening parenthesis
(?<name> exp)
Creates a named subexpression that captures the matching substring. The name must not contain any punctuation and must begin with a letter. Single quotes may be used in place of angle brackets
(?: exp)
Creates an unnamed subexpression that does not capture the matching substring (for precedence only)
(?imnsx-imnsx: exp)
Enables or disables regular expression matching options within the subexpression
 
The numbering of named capture groups is also based on the order of opening parenthesis, but starts after all the unnamed captures have been counted.  
 
The options have the following meanings:  
i
Case insensitive matching (?i:) or case sensitive matching (?-i)
m
Treats the matched text as a multiline string (default)
s
Treats the matched text as a single line string
n
Explicit capture. Only captures substrings for explicitly named capture groups (?<name>) and not for regular/unnamed (...) groups
x
Excludes unescaped whitespace outside of character classes from the pattern
 
 
Alternation  
Alternation constructs allow the regular expression to match one of several alternatives.  
|
Matches any of the terms separated by the | (vertical bar) character. The first/leftmost successful match is used.
(?(expression)yes|no)
Matches the "yes" part if the expression matches at this point; otherwise, matches the "no" part. The "no" part is optional.
 
 
Backreferences  
Backreferences are used to match text based on previously captured groups.  
\number
Matches the text captured by the given capture (specified by number)
\k<name>
Matches the text captured by the given named capture
 
 
Substitutions in Replace Pattern  
Substitutions allow captured text to be used in the replace pattern, thus making the replacement text depend on the text that is matched. They are only allowed when Use Regular Expressions is checked.  
 
$number
Replaced with the captured substring matched by the group with the given number ($0 is the entire matched text)
${name}
Replaced with the captured substring matched by the group with the given name
$$
Replaced with a single '$' literal (escape)
$&
Replaced with the entire matched text
$`
Replaced with the input string before the match
$'
Replaced with the rest of the input string after the match
$+
Replaced with the captured substring of the last group that was matched
$_
Replaced with the entire input string
 

Note: since the '$' character takes on special significance in replacement pattern when the Use Regular Expressions box is checked, the escape sequence $$ must be used when a single '$' character is desired in the replacement text  
 
See Also  
Find/Replace Diagram and Element Text | Diagram Tasks  
 

Copyright (c) 2006 by Effexis Software, LLC
Looking for a time management or goal setting solution? Try our Time Management Software
See also Time management and goal setting guides to make better use of your time and learn how to set and achieve your important goals.
Site Links Time management software : to-do list software : sequence diagrams : time management system : daily planner
Visio UML Sequence Diagrams :
goal setting software