📚 [Tutorial] ReplaceFirst implementation

by Herman Semin

Version 1 (March 11, 2019)

Download (996 downloads)

Difficulty: easy/below average (regular expressions, 3 variable blocks, can be combined into a one)
A simple implementation of replace/replaceFirst function which is not on Automate.

Pre-scriptum: I was really surprised when I found out that there is no "replaceFirst/replace" function which replace only first occurrence met. So, after a little brainstorm and a bit of regular expression tricks I've made something really lookalike. Hope it really works as replace() works, though I tested it on a few test strings.

Input blocks - accept any text, including none (.* regular expression)
Variable blocks - pattern ^(.*?){regex} matches just one occurrence of regular expression anywhere in text and captures everything before this occurence; replacement text $1{replacement} contains a group reference $1, which is explained above.
In the end, a replaceAll() function is applied to the input string with regex and replacement (explained above)

5.0 average rating from 6 reviews

5 stars
4 stars
3 stars
2 stars
1 star

Rate and review within the app in the Community section.