Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtin function replace does not support positional patterns #347

Open
catull opened this issue May 23, 2024 · 1 comment
Open

builtin function replace does not support positional patterns #347

catull opened this issue May 23, 2024 · 1 comment

Comments

@catull
Copy link

catull commented May 23, 2024

In issue #340 I had to resort to 2 nested replace calls.

replace (
    replace (text, ",]", ]),
    ",}", "}
)

I wanted to collapse the two nested calls into one.
Both patterns start with ,, one ends with }, while the other ends in ].

It would be great if this was supported:

replace (input, ",([}\])", "$1")

This way, ,} would result in }, and ,] would become ']'.

Or think of the eternal battle of date formats, ISO vs US format vs European.

def isoDateToUS (date)
  replace (date, "(\d\d\d\d)-(\d\d)-(\d\d)", "$2/$3/$1"

def isoDateToEuropean (date)
  replace (date, "(\d\d\d\d)-(\d\d)-(\d\d)", "$3/$3/$1"

I am not going to suggest that this be supported in this issue:

def isoToUSformat (date)
  replace (date, "(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})", "${month}/${day}/${year}")
@catull catull changed the title builtin function replace deos not support positional patterns builtin function replace does not support positional patterns May 23, 2024
@catull
Copy link
Author

catull commented May 23, 2024

This issue can be seen as an extension of #346, I realize it now.

catull pushed a commit to catull/jslt that referenced this issue May 26, 2024
catull pushed a commit to catull/jslt that referenced this issue May 26, 2024
This PR addresses issues schibsted#346 and schibsted#347.
Added documentation.
catull pushed a commit to catull/jslt that referenced this issue May 26, 2024
This PR addresses issues schibsted#346 and schibsted#347.
Added documentation.
catull pushed a commit to catull/jslt that referenced this issue May 26, 2024
This PR addresses issues schibsted#346 and schibsted#347.
Added support for Regexp pattern "Predefined character classes".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant