📚 [Tutorial] ReplaceFirst implementation

by KeterDev

Version 1 (March 11, 2019)

Download (131 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.

Explanation:
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)

4.0 average rating from 4 reviews

5 stars
3
4 stars
0
3 stars
0
2 stars
0
1 star
1
Warnings
0

Reviews and ratings can be submitted in the app.