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

Regex: Cannot escape special characters #1209

Closed
archetyped opened this issue Mar 1, 2023 · 1 comment · Fixed by #1212
Closed

Regex: Cannot escape special characters #1209

archetyped opened this issue Mar 1, 2023 · 1 comment · Fixed by #1212
Assignees
Labels

Comments

@archetyped
Copy link

Some special characters such as ^ and $ cannot be escaped (to use as a literal character) in regular expressions.

Example:

echo 'd\n$test\ntest$middle' | mlr --c2p put '$d = sub($d, "^\$", "Dollar")'

Output:

mlr: cannot parse DSL expression.
Parse error on token ""^\$" at line 1 column 14.
Expected one of:
  { ( ) field_name $[ braced_field_name $[[ $[[[ full_srec oosvar_name @[
  braced_oosvar_name full_oosvar all non_sigil_name float int + - .+ .- !
  ~ string_literal regex_case_insensitive int_literal float_literal boolean_literal
  null_literal inf_literal nan_literal const_M_PI const_M_E panic [ ctx_IPS
  ctx_IFS ctx_IRS ctx_OPS ctx_OFS ctx_ORS ctx_FLATSEP ctx_NF ctx_NR ctx_FNR
  ctx_FILENAME ctx_FILENUM env func

Notes

  • Miller version: 6.6.0
  • Other discussions have referenced using ssub(), but that will not work in situations like the above example where the position of the special character is important.
  • This is similar to some previous tickets (e.g. Escape dollar sign in regular expressions #171), but they appear to be related to pre-Go versions of Miller, where regex handling may be different, so it felt best to create a separate ticket.
@johnkerl
Copy link
Owner

johnkerl commented Mar 1, 2023

@archetyped thank you!! Your example above has been included as a unit-test case in #1212.

@johnkerl johnkerl removed the active label Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants