Page MenuHomePhabricator

Implement "replace" transformation step
Closed, ResolvedPublicFeature

Description

The following transformation steps should be implemented as soon as possible, as they would be particularly useful to start experimenting with the initial releases of Web2Cit-Core and Web2Cit-Server:

  • "replace" transformation: replaces a substring or regular expression with another string
  • "match" transformation: isolates substrings matching a target

Event Timeline

Match transformation step type implemented in b037845a.

diegodlh renamed this task from Implement "replace" and "match" transformation steps to Implement "replace" transformation step.Mar 9 2022, 2:39 PM
diegodlh updated the task description. (Show Details)
diegodlh changed the subtype of this task from "Task" to "Feature Request".Aug 31 2022, 2:30 PM
diegodlh removed a project: Web2Cit-Core (v0.0.1).

It is worth noting that in the meantime, as a workaround, one may use a Split transformation followed by a Join transformation, as suggested by @Kerry_Raymond. However, Split transformation does not support regular expressions.

Regarding Replace transformation, how do we distinguish pattern and replacement parameters in the config value while T305903 is not supported?

We may use a syntax similar to sed substitution: /pattern/replacement/flags. We should note syntax is sed-like, but it is NOT sed.

This would be used as String.prototype.replace(/pattern/flags, replacement), with /pattern/flags as regular expression and replacement as string.

Special replacement patterns would be supported as indicated in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement.

A simpler pattern/replacement syntax may be supported for simpler replacements, with both pattern and replacement interpreted as strings.

Special replacement patterns would be supported

It should also be noted that, as a result, literal $ characters should be escaped in replacement parameter as $$.

diegodlh changed the task status from Open to In Progress.May 7 2026, 8:08 PM

Replace transformation inplemented in Web2Cit-Core with 230f83c6.

Pending documentation update in https://meta.wikimedia.org/wiki/Web2Cit/Docs/Templates#Replace_transformation_(proposed).

Pending w2c-core library update in Web2Cit-Server and deploy.

Added Replacement transformation to templates schema with 7b9a4f91.

diegodlh claimed this task.

Deployed with w2c-server 1.4.0