Skip to content

Commit

Permalink
馃殤 Allow for regex without slashes for retro compat
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 2, 2024
1 parent a0ba8c5 commit 2663ca2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ const parseValuePlaceholder = (
return ''
case ComparisonOperators.MATCHES_REGEX:
case ComparisonOperators.NOT_MATCH_REGEX:
return '^[0-9]+$'
return '/^[0-9]+$/'
}
}
2 changes: 2 additions & 0 deletions apps/docs/editor/blocks/logic/condition.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Example:

- `/^hello$/` will match if the string is strictly equal to "hello".
- `/hello/` will match if the string contains "hello". Like "hello world".
- `/hello/i` will match if the string contains "hello" case-insensitive. Like "Hello world".
- `/[0-9]+/` will match if the string contains one or more digits. Like "123".

</ResponseField>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ const parseDateOrNumber = (value: string): number => {
}

const preprocessRegex = (regex: string) => {
const match = regex.match(/^\/([^\/]+)\/([gimuy]*)$/)
const regexWithFlags = regex.match(/\/(.+)\/([gimuy]*)$/)

if (!match) return null
if (regexWithFlags)
return { pattern: regexWithFlags[1], flags: regexWithFlags[2] }

return { pattern: match[1], flags: match[2] }
return { pattern: regex }
}

0 comments on commit 2663ca2

Please sign in to comment.