forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.lcdoc
More file actions
145 lines (111 loc) · 4.89 KB
/
Copy pathfilter.lcdoc
File metadata and controls
145 lines (111 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Name: filter
Type: command
Syntax: filter [{lines | items | keys | elements} of] <filterSource> {with | without | [not] matching} [{wildcard pattern | regex pattern}] <filterPattern> [into <targetContainer>]
Summary:
Filters each line, item, key or element in a source container or
expression, removing the lines, items, keys or elements that do or don't
match a pattern.
Introduced: 1.0
OS: mac, windows, linux, ios, android
Platforms: desktop, server, mobile
Example:
local tVar
put the propertyNames into tVar
filter tVar with "[az]*"
-- tVar contains all property names beginning with a or z
Example:
-- Filtering a string literal causes the filtered string to be placed in the it variable
filter items of "apple,banana,cherry" with regex pattern "b.*"
-- it contains "banana"
Example:
local tSource, tBackscriptObjects
put the backscripts into tSource
filter lines of tSource without regex pattern "^stack.*" into tBackscriptObjects
-- tBackscriptObjects contains a list of non-stack backscripts
Example:
create field "Numbers"
put "123,234,345,456,567,678,789" into field "Numbers"
filter items of field "Numbers" matching "*[!35-9]"
-- field contains "234"
Example:
local tArray
put true into tArray["foo"]
put false into tArray["bar"]
filter keys of tArray with "f*"
put the keys of tArray is "foo"
Example:
local tArray
put true into tArray["foo"]
put false into tArray["bar"]
filter elements of tArray without "f*"
put the keys of tArray is "foo"
Parameters:
filterSource:
An expression that evaluates to a string, array, or a container.
filterPattern:
An expression used to match certain lines, items, keys or elements.
targetContainer:
An expression that evaluates to a container
It:
If the filter command is used on a <filterSource> which is not a
container, and no <targetContainer> is specified, the filtered string
or array will be placed in the <it> variable.
Description:
Use the <filter> command to pick specific lines, items, keys or elements
in a container or expression.
The <filter>...with form and the <filter>...matching form retain the
lines, items, keys or elements that contain a match for the specified
<filterPattern>.
The <filter>...without form and the <filter>...not matching form discard
the lines, items, keys or elements that do not contain a match for the
specified <filterPattern>.
If you don't specify lines, items, keys or elements then lines are
filtered by default.
If a regex pattern is specified, the <filterPattern> evaluates to a
regular expression.
If a wildcard <filterPattern> is specified, the <filterPattern> consists
of a string of characters to match, which may be combined with any
number of the following special characters:
- * : Matches zero or more of any character. The <filterPattern> A*C
matches "AC", "ABC", or "ADZXC".
- ? : Matches exactly one character. The <filterPattern> A?C matches
"ABC", but not "AC" or "ADZXC".
- [chars] : Matches any one of the characters inside the brackets. The
<filterPattern> A[BC]D matches "ABD" or "ACD", but not "AD" or "ABCD".
- [char-char] : Matches any character whose unicode codepoint is between
the first character and the second character.
- [!chars] : Matches any character which is not one of the characters
inside the brackets.
You can match instances of special chars as follows:
- `?` with `[?]`
- `*` with `[*]`
- `[` with `[[]`
- `-` with `-`
- `!` with `!`
For example, the wildcard <filterPattern> `[[]A]*` will match any
string beginning with `[A]`.
The three bracketed forms can be combined to create more complex
character classes, for example the pattern [!abcA-C] matches any
character which is not a, b or c (upper or lower case)
If no <filterPattern> type is specified, the <filterPattern> is handled
as a wildcard.
If no <targetContainer> is specified, and you filter a container, the
container contents will be replaced by the filtered result.
Changes:
The <filter>...without form was added in version 2.1.1. In previous
versions, the <filter> command could be used only to retrieve lines that
matched a wildcard expression. The <filter> items... form was added in
version 6.1. In previous versions, the <filter> command could be used
only to retrieve lines. The ability to filter using a regular expression
was added in version 6.1. In previous versions, the <filter> command
only supported wildcard expressions. The ability to filter an expression
was added in version 6.1. In previous versions, the <filter> command
could be used only for a container. The <filter>...[not] matching form
was added in version 6.1 to clarify the pattern handling. The
<filter>...into form was added in version 6.1. In previous versions, the
filter command always replaced the contents of the original container.
Filtering of array keys and elements was added in version 8.1.
References: replace (command), sort (command), matchChunk (function),
matchText (function), replaceText (function), it (keyword),
caseSensitive (property)
Tags: text processing