You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This query will return all items where the email matches the pattern `@example.com` or `@example.org`.
26
+
27
+
## Flags
28
+
29
+
You can modify the behavior of the regex matching by providing flags. Flags are specified using the `params` option:
30
+
31
+
```ts twoslash
32
+
import { query } from'@chronicstone/array-query'
33
+
34
+
const data = [
35
+
{ id: 1, name: 'John Doe' },
36
+
{ id: 2, name: 'jane smith' },
37
+
{ id: 3, name: 'Bob Johnson' }
38
+
]
39
+
40
+
const result =query(data, {
41
+
filter: [
42
+
{
43
+
key: 'name',
44
+
matchMode: 'regex',
45
+
value: '^j.*',
46
+
params: { flags: 'i' }
47
+
}
48
+
]
49
+
})
50
+
```
51
+
52
+
## Raw RegExp
53
+
54
+
Instead of defining the regex pattern as a string, you can also pass a regular expression object directly:
55
+
56
+
```ts twoslash
57
+
import { query } from'@chronicstone/array-query'
58
+
59
+
const data = [
60
+
{ id: 1, name: 'John Doe' },
61
+
{ id: 2, name: 'jane smith' },
62
+
{ id: 3, name: 'Bob Johnson' }
63
+
]
64
+
65
+
const result =query(data, {
66
+
filter: [
67
+
{
68
+
key: 'name',
69
+
matchMode: 'regex',
70
+
value:/^j.*/i
71
+
}
72
+
]
73
+
})
74
+
```
75
+
76
+
For a detailed explanation of available flags and their usage, please refer to the [MDN documentation on Regular Expression Flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags).
This will find items where the name starts with 'j' (case-insensitive) AND the age is greater than 28.
149
+
150
+
## Performance Considerations
151
+
152
+
While regex matching is powerful, it can be computationally expensive, especially on large datasets or with complex patterns. Use it judiciously and consider performance implications in your use case.
153
+
154
+
## Escaping Special Characters
155
+
156
+
Remember to properly escape special regex characters in your pattern strings. For example, to match a literal period, use `\\.` instead of `.`.
157
+
158
+
## Further Reading
159
+
160
+
For more information on JavaScript regular expressions, including pattern syntax and usage, refer to the [MDN Regular Expressions Guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions).
0 commit comments