Skip to content

Commit 08e3acd

Browse files
authored
feat(firestore): add support for regexFind and regexFindAll (#9459)
1 parent d818df4 commit 08e3acd

12 files changed

Lines changed: 1341 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'firebase': minor
3+
'@firebase/firestore': minor
4+
---
5+
6+
Add support for `regexFind` and `regexFindAll` Pipeline expressions.

common/api-review/firestore-lite-pipelines.api.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,14 @@ export abstract class Expression {
544544
/* Excluded from this release type: _readUserData */
545545
regexContains(pattern: Expression): BooleanExpression;
546546
/* Excluded from this release type: _readUserData */
547+
regexFind(pattern: string): FunctionExpression;
548+
/* Excluded from this release type: _readUserData */
549+
regexFind(pattern: Expression): FunctionExpression;
550+
/* Excluded from this release type: _readUserData */
551+
regexFindAll(pattern: string): FunctionExpression;
552+
/* Excluded from this release type: _readUserData */
553+
regexFindAll(pattern: Expression): FunctionExpression;
554+
/* Excluded from this release type: _readUserData */
547555
regexMatch(pattern: string): BooleanExpression;
548556
/* Excluded from this release type: _readUserData */
549557
regexMatch(pattern: Expression): BooleanExpression;
@@ -1021,6 +1029,30 @@ export function regexContains(stringExpression: Expression, pattern: string): Bo
10211029
// @beta
10221030
export function regexContains(stringExpression: Expression, pattern: Expression): BooleanExpression;
10231031

1032+
// @beta
1033+
export function regexFind(fieldName: string, pattern: string): FunctionExpression;
1034+
1035+
// @beta
1036+
export function regexFind(fieldName: string, pattern: Expression): FunctionExpression;
1037+
1038+
// @beta
1039+
export function regexFind(stringExpression: Expression, pattern: string): FunctionExpression;
1040+
1041+
// @beta
1042+
export function regexFind(stringExpression: Expression, pattern: Expression): FunctionExpression;
1043+
1044+
// @beta
1045+
export function regexFindAll(fieldName: string, pattern: string): FunctionExpression;
1046+
1047+
// @beta
1048+
export function regexFindAll(fieldName: string, pattern: Expression): FunctionExpression;
1049+
1050+
// @beta
1051+
export function regexFindAll(stringExpression: Expression, pattern: string): FunctionExpression;
1052+
1053+
// @beta
1054+
export function regexFindAll(stringExpression: Expression, pattern: Expression): FunctionExpression;
1055+
10241056
// @beta
10251057
export function regexMatch(fieldName: string, pattern: string): BooleanExpression;
10261058

common/api-review/firestore-pipelines.api.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,14 @@ export abstract class Expression {
547547
/* Excluded from this release type: _readUserData */
548548
regexContains(pattern: Expression): BooleanExpression;
549549
/* Excluded from this release type: _readUserData */
550+
regexFind(pattern: string): FunctionExpression;
551+
/* Excluded from this release type: _readUserData */
552+
regexFind(pattern: Expression): FunctionExpression;
553+
/* Excluded from this release type: _readUserData */
554+
regexFindAll(pattern: string): FunctionExpression;
555+
/* Excluded from this release type: _readUserData */
556+
regexFindAll(pattern: Expression): FunctionExpression;
557+
/* Excluded from this release type: _readUserData */
550558
regexMatch(pattern: string): BooleanExpression;
551559
/* Excluded from this release type: _readUserData */
552560
regexMatch(pattern: Expression): BooleanExpression;
@@ -1058,6 +1066,30 @@ export function regexContains(stringExpression: Expression, pattern: string): Bo
10581066
// @beta
10591067
export function regexContains(stringExpression: Expression, pattern: Expression): BooleanExpression;
10601068

1069+
// @beta
1070+
export function regexFind(fieldName: string, pattern: string): FunctionExpression;
1071+
1072+
// @beta
1073+
export function regexFind(fieldName: string, pattern: Expression): FunctionExpression;
1074+
1075+
// @beta
1076+
export function regexFind(stringExpression: Expression, pattern: string): FunctionExpression;
1077+
1078+
// @beta
1079+
export function regexFind(stringExpression: Expression, pattern: Expression): FunctionExpression;
1080+
1081+
// @beta
1082+
export function regexFindAll(fieldName: string, pattern: string): FunctionExpression;
1083+
1084+
// @beta
1085+
export function regexFindAll(fieldName: string, pattern: Expression): FunctionExpression;
1086+
1087+
// @beta
1088+
export function regexFindAll(stringExpression: Expression, pattern: string): FunctionExpression;
1089+
1090+
// @beta
1091+
export function regexFindAll(stringExpression: Expression, pattern: Expression): FunctionExpression;
1092+
10611093
// @beta
10621094
export function regexMatch(fieldName: string, pattern: string): BooleanExpression;
10631095

docs-devsite/firestore_lite_pipelines.expression.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ field("optional_field").ifAbsent(field('default_field'))
128128
| [pow(exponent)](./firestore_lite_pipelines.expression.md#expressionpow) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the value of this expression raised to the power of a constant value. |
129129
| [regexContains(pattern)](./firestore_lite_pipelines.expression.md#expressionregexcontains) | | <b><i>(Public Preview)</i></b> Creates an expression that checks if a string contains a specified regular expression as a substring. |
130130
| [regexContains(pattern)](./firestore_lite_pipelines.expression.md#expressionregexcontains) | | <b><i>(Public Preview)</i></b> Creates an expression that checks if a string contains a specified regular expression as a substring. |
131+
| [regexFind(pattern)](./firestore_lite_pipelines.expression.md#expressionregexfind) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the first substring of a string expression that matches a specified regular expression.<!-- -->This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax. |
132+
| [regexFind(pattern)](./firestore_lite_pipelines.expression.md#expressionregexfind) | | <b><i>(Public Preview)</i></b> Creates an expression that returns the first substring of a string expression that matches a specified regular expression.<!-- -->This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax. |
133+
| [regexFindAll(pattern)](./firestore_lite_pipelines.expression.md#expressionregexfindall) | | <b><i>(Public Preview)</i></b> Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.<!-- -->This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax. |
134+
| [regexFindAll(pattern)](./firestore_lite_pipelines.expression.md#expressionregexfindall) | | <b><i>(Public Preview)</i></b> Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.<!-- -->This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax. |
131135
| [regexMatch(pattern)](./firestore_lite_pipelines.expression.md#expressionregexmatch) | | <b><i>(Public Preview)</i></b> Creates an expression that checks if a string matches a specified regular expression. |
132136
| [regexMatch(pattern)](./firestore_lite_pipelines.expression.md#expressionregexmatch) | | <b><i>(Public Preview)</i></b> Creates an expression that checks if a string matches a specified regular expression. |
133137
| [reverse()](./firestore_lite_pipelines.expression.md#expressionreverse) | | <b><i>(Public Preview)</i></b> Creates an expression that reverses this string expression. |
@@ -2868,6 +2872,150 @@ field("description").regexContains(field("regex"));
28682872

28692873
```
28702874

2875+
## Expression.regexFind()
2876+
2877+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
2878+
>
2879+
2880+
Creates an expression that returns the first substring of a string expression that matches a specified regular expression.
2881+
2882+
This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax.
2883+
2884+
<b>Signature:</b>
2885+
2886+
```typescript
2887+
regexFind(pattern: string): FunctionExpression;
2888+
```
2889+
2890+
#### Parameters
2891+
2892+
| Parameter | Type | Description |
2893+
| --- | --- | --- |
2894+
| pattern | string | The regular expression to search for. |
2895+
2896+
<b>Returns:</b>
2897+
2898+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2899+
2900+
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the regular expression find function.
2901+
2902+
### Example
2903+
2904+
2905+
```typescript
2906+
// Extract the domain from an email address
2907+
field("email").regexFind("@.+")
2908+
2909+
```
2910+
2911+
## Expression.regexFind()
2912+
2913+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
2914+
>
2915+
2916+
Creates an expression that returns the first substring of a string expression that matches a specified regular expression.
2917+
2918+
This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax.
2919+
2920+
<b>Signature:</b>
2921+
2922+
```typescript
2923+
regexFind(pattern: Expression): FunctionExpression;
2924+
```
2925+
2926+
#### Parameters
2927+
2928+
| Parameter | Type | Description |
2929+
| --- | --- | --- |
2930+
| pattern | [Expression](./firestore_lite_pipelines.expression.md#expression_class) | The regular expression to search for. |
2931+
2932+
<b>Returns:</b>
2933+
2934+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2935+
2936+
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the regular expression find function.
2937+
2938+
### Example
2939+
2940+
2941+
```typescript
2942+
// Extract the domain from an email address
2943+
field("email").regexFind(field("domain"))
2944+
2945+
```
2946+
2947+
## Expression.regexFindAll()
2948+
2949+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
2950+
>
2951+
2952+
Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.
2953+
2954+
This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax.
2955+
2956+
<b>Signature:</b>
2957+
2958+
```typescript
2959+
regexFindAll(pattern: string): FunctionExpression;
2960+
```
2961+
2962+
#### Parameters
2963+
2964+
| Parameter | Type | Description |
2965+
| --- | --- | --- |
2966+
| pattern | string | The regular expression to search for. |
2967+
2968+
<b>Returns:</b>
2969+
2970+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
2971+
2972+
A new [Expression](./firestore_pipelines.expression.md#expression_class) that evaluates to an array of matched substrings.
2973+
2974+
### Example
2975+
2976+
2977+
```typescript
2978+
// Extract all hashtags from a post content field
2979+
field("content").regexFindAll("#[A-Za-z0-9_]+")
2980+
2981+
```
2982+
2983+
## Expression.regexFindAll()
2984+
2985+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
2986+
>
2987+
2988+
Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.
2989+
2990+
This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax.
2991+
2992+
<b>Signature:</b>
2993+
2994+
```typescript
2995+
regexFindAll(pattern: Expression): FunctionExpression;
2996+
```
2997+
2998+
#### Parameters
2999+
3000+
| Parameter | Type | Description |
3001+
| --- | --- | --- |
3002+
| pattern | [Expression](./firestore_lite_pipelines.expression.md#expression_class) | The regular expression to search for. |
3003+
3004+
<b>Returns:</b>
3005+
3006+
[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)
3007+
3008+
A new [Expression](./firestore_pipelines.expression.md#expression_class) that evaluates to an array of matched substrings.
3009+
3010+
### Example
3011+
3012+
3013+
```typescript
3014+
// Extract all names from a post content field
3015+
field("content").regexFindAll(field("names"))
3016+
3017+
```
3018+
28713019
## Expression.regexMatch()
28723020

28733021
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

0 commit comments

Comments
 (0)