s
Input Stack:
|
⇨ | Output Stack:
|
Perform search and replace operations on legend text using regular expressions. This operator
provides powerful text transformation capabilities similar to the global search and replace
operations found in text editors and command-line tools like sed
or vim
.
Parameters¶
- expr: The time series expression whose legend text will be modified
- searchPattern: Regular expression pattern to search for in the legend text
- replacement: Replacement text that can include capture group references
Pattern Syntax¶
The search pattern uses standard regular expression syntax with support for:
- Literal text: Direct string matching (e.g.,
nccp-
matches the literal text "nccp-") - Character classes:
[a-z]
matches any lowercase letter - Anchors:
^
(start of string),$
(end of string) - Quantifiers:
*
(zero or more),+
(one or more),?
(zero or one) - Grouping:
(...)
creates capture groups for use in replacement
Replacement Variables¶
The replacement string supports variable substitution using the same syntax as :legend:
Capture Group References¶
- Numbered groups:
$1
,$2
, etc. refer to capture groups by position - Named groups:
$name
refers to named capture groups like(?<name>...)
Standard Variables¶
- Tag values:
$tagname
substitutes tag values from the time series - Special variables:
$atlas.offset
and other system variables
Examples¶
Removing Prefixes¶
Remove the "nccp-" prefix from cluster names:
Before | After |
name,sps,:eq, (,nf.cluster,),:by, $nf.cluster,:legend | name,sps,:eq, (,nf.cluster,),:by, $nf.cluster,:legend, ^nccp-(.*)$,$1,:s |
Named Capture Groups¶
Using named groups for clearer replacement patterns:
Before | After |
name,sps,:eq, (,nf.cluster,),:by, $nf.cluster,:legend | name,sps,:eq, (,nf.cluster,),:by, $nf.cluster,:legend, ^nccp-(? |
Simple Text Replacement¶
Replace literal text without regex patterns:
Before | After |
name,sps,:eq, (,nf.cluster,),:by, $nf.cluster,:legend | name,sps,:eq, (,nf.cluster,),:by, $nf.cluster,:legend, nccp-,_,:s |
Pattern-Based Transformation¶
Transform character patterns with replacement:
Before | After |
name,sps,:eq, (,nf.cluster,),:by, $nf.cluster,:legend | name,sps,:eq, (,nf.cluster,),:by, $nf.cluster,:legend, ([a-z]),_$1,:s |
Processing Order¶
When applied to time series with multiple legend values, the search and replace operation is performed independently on each legend string. The operation affects only the display text and does not modify the underlying tag values.
Related Operations¶
- :legend - Set custom legend text with variable substitution
- :decode - Decode encoded characters in legend text
- :as - Rename tag keys for mathematical operations
- :format - Create formatted strings with printf-style patterns
Since: 1.6