Menu

Removing a substring

Rx (9)
Oleg Osepyants

Removing a substring

Despite the fact that the Rx language does not have a DELETE statement, there are as many as three ways to delete something from the text using Rx language operators. Let's look at all three with examples.

Examples

Example 1

The most obvious way to remove something from the text is to replace the desired substring with an empty string.

REPLACE R"<strike>.*?</strike>" TO P""

Original text

<p>This is my <strike>super duper</strike> test paragraph.</p>

The text after applying the statement above

<p>This is my  test paragraph.</p>

Example 2

Another way to do this is to replicate the searched string zero times, which will cause it to be deleted.

REPLICATE R"<strike>.*?</strike>" 0 TIMES

Original text

<p>This is my <strike>super duper</strike> test paragraph.</p>

The text after applying the statement above

<p>This is my  test paragraph.</p>

Example 3

And finally - the third, most non-obvious way: to copy-paste an empty string into the one to be deleted.

COPYPASTE P"" TO R"<strike>.*?</strike>"

Original text

<p>This is my <strike>super duper</strike> test paragraph.</p>

The text after applying the statement above

<p>This is my  test paragraph.</p>

Related

Wiki: Rx text transformation script language

MongoDB Logo MongoDB