@@ -2,12 +2,13 @@ Name: filter
22
33Type: command
44
5- Syntax: filter [{lines | items | keys | elements} of] <filterSource> {with | without | [not] matching} [{wildcard pattern | regex pattern}] <filterPattern> [into <targetContainer>]
5+ Syntax: filter [{lines | items | keys | elements} of] <filterSource> {with| without | [not] matching} [wildcard pattern] <wildcardPattern> [into <targetContainer>]
6+
7+ Syntax: filter [{lines | items | keys | elements} of] <filterSource> {with| without | [not] matching} regex pattern <regexPattern> [into <targetContainer>]
68
79Summary:
8- Filters each line, item, key or element in a source container or
9- expression, removing the lines, items, keys or elements that do or don't
10- match a pattern.
10+ Filters each line, item, key or element in a source container or expression,
11+ removing the lines, items, keys or elements that do or don't match a pattern.
1112
1213Introduced: 1.0
1314
@@ -56,49 +57,60 @@ Parameters:
5657filterSource:
5758An expression that evaluates to a string, array, or a container.
5859
59- filterPattern :
60+ wildcardPattern :
6061An expression used to match certain lines, items, keys or elements.
62+ See description.
63+
64+ regexPattern:
65+ An regular expression used to match certain lines, items, keys or elements.
66+ See [Microsoft's RegEx Quick Reference](https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference)
67+ guide for more info on regex usage.
6168
6269targetContainer:
63- An expression that evaluates to a container
70+ An expression that evaluates to a container.
6471
6572It:
66- If the filter command is used on a <filterSource> which is not a
67- container, and no <targetContainer> is specified, the filtered string
73+ If the filter command is used on a <filterSource> which is not
74+ a < container> , and no <targetContainer> is specified, the filtered string
6875or array will be placed in the <it> variable.
6976
7077Description:
7178Use the <filter> command to pick specific lines, items, keys or elements
72- in a container or expression.
79+ in a < container> or < expression> .
7380
74- The < filter> ...with form and the < filter> ...matching form retain the
81+ The ` filter...with` form and the ` filter...matching` form retain the
7582lines, items, keys or elements that contain a match for the specified
76- <filterPattern >.
83+ <wildcardPattern> or <regexPattern >.
7784
78- The < filter> ...without form and the < filter> ...not matching form discard
85+ The ` filter...without` form and the ` filter...not matching` form discard
7986the lines, items, keys or elements that do not contain a match for the
80- specified <filterPattern>.
87+ specified <wildcardPattern> or <regexPattern>.
8188
8289If you don't specify lines, items, keys or elements then lines are
8390filtered by default.
8491
85- If a regex pattern is specified, the <filterPattern> evaluates to a
86- regular expression .
92+ >**Note:** If neither `wildcard pattern` or `regex pattern` forms are explicitly
93+ specified then the wildcard pattern form is assumed .
8794
88- If a wildcard <filterPattern> is specified, the <filterPattern> consists
89- of a string of characters to match, which may be combined with any
95+ If the `regex pattern` form is specified, the <regexPattern> should
96+ be formatted as a <regular expression>. There are [many websites](https://www.google.com/search?regex)
97+ that provide examples and tutorials of RegEx expressions.
98+
99+ If the 'wildcard pattern' form is to be used, the <wildcardPattern> should
100+ consists of a string of characters to match, which may be combined with any
90101number of the following special characters:
91102
92- - * : Matches zero or more of any character. The < filterPattern> A*C
103+ - `*` : Matches zero or more of any character. The filterPattern ` A*C`
93104 matches "AC", "ABC", or "ADZXC".
94- - ? : Matches exactly one character. The < filterPattern> A?C matches
105+ - `?` : Matches exactly one character. The filterPattern ` A?C` matches
95106 "ABC", but not "AC" or "ADZXC".
96- - [chars] : Matches any one of the characters inside the brackets. The
97- <filterPattern> A[BC]D matches "ABD" or "ACD", but not "AD" or "ABCD".
98- - [char-char] : Matches any character whose unicode codepoint is between
99- the first character and the second character.
100- - [!chars] : Matches any character which is not one of the characters
107+ - `[chars]` : Matches any one of the characters inside the brackets. The
108+ filterPattern `A[BC]D` matches "ABD" or "ACD", but not "AD" or "ABCD".
109+ - `[!chars]` : Matches any character which is not one of the characters
101110 inside the brackets.
111+ - `[char-char]` : Matches any character whose unicode codepoint is between
112+ the first character and the second character, such as `[a-y]` any character
113+ between "a" and "y" but not "z"
102114
103115
104116You can match instances of special chars as follows:
@@ -110,18 +122,17 @@ You can match instances of special chars as follows:
110122- `!` with `!`
111123
112124
113- For example, the wildcard <filterPattern> `[[]A]*` will match any
114- string beginning with `[A]`.
125+ For example, the <wildcardPattern> `[[]A]*` will match any
126+ string beginning with `[A]`. Broken down, there is `[[]` which equates
127+ to an open square bracket `[` followed by `A]*` as the closing square
128+ bracket is not a special character.
115129
116130The three bracketed forms can be combined to create more complex
117131character classes, for example the pattern [!abcA-C] matches any
118132character which is not a, b or c (upper or lower case)
119133
120- If no <filterPattern> type is specified, the <filterPattern> is handled
121- as a wildcard.
122-
123- If no <targetContainer> is specified, and you filter a container, the
124- container contents will be replaced by the filtered result.
134+ If no <targetContainer> is specified, and you filter a <container>,
135+ the <container> contents will be replaced by the filtered result.
125136
126137Changes:
127138The <filter>...without form was added in version 2.1.1. In previous
@@ -140,6 +151,7 @@ Filtering of array keys and elements was added in version 8.1.
140151
141152References: replace (command), sort (command), matchChunk (function),
142153matchText (function), replaceText (function), it (keyword),
143- caseSensitive (property)
154+ caseSensitive (property), container (glossary), expression (glossary),
155+ regular expression (glossary)
144156
145157Tags: text processing
0 commit comments