r/tasker•
arjun2502

[help] hi, is it possible to add full point (.) after every 4 words in a sentence/paragraph?

Help

[help] hi, is it possible to add full point (.) after every 4 words in a sentence/paragraph using variable search replace? I searched for regex matching , didn't understand a thing as I am not from programming background. Thank you.

Posted Dec 21, 2020, 2:51 AM UTC

06
UnkleMike•

Variable Search Replace should do it.

Add . 4 Words (305)
	A1: Variable Set [ Name:%string To:this is a sentence with more than eight words in it Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ] 
	A2: Variable Search Replace [ Variable:%string Search:(\w+\s+\w+\s+\w+\s+\w+) Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In Array:%matches Replace Matches:On Replace With:$1. ] 
	A3: Flash [ Text:%string Long:Off ] 

In the search pattern, \w+ is a series of word characters, and \s+ is a series of whitespace characters. In the replace string, $1 refers to the matched text (i.e. a string of 4 words separated by whitespace) and adds a . to the end.

No attempt is made to deal with a number of words that's not a multiple of 4, so the final 3 words don't get a . appended.

4
arjun2502OP•

Hi u/UncleMike , Wow, you made it look so easy, with that explanation. That solved my problem. Thanks a ton. Have a good day.

1
Rich_D_sr•

Have you tried splitting on a space then iterating through the array appending it back together and adding the <.> On every 4th iteration?

2
arjun2502OP•

Hi, thanks a lot for help. I will try this also.

1
FacepalmNation•

RegEx is required for variable search replace. How I learned variable search replace is I followed the advice given here. It is a harder concept to understand, but your Diligence will eventually pay off.

2
arjun2502OP•

Hi, thanks a lot for the help. I will go through it .

1