Remove the first word from a variable

721 views
Skip to first unread message

Mefistofelis

unread,
Jun 19, 2014, 11:24:06 AM6/19/14
to tas...@googlegroups.com
I am trying to remove the first word of a tweet which is as variable in tasker- the first word is always the username- and keep the rest of the tweet however I don't know how to do that since the username varies in length and the tweet varies in length too.

For example the tweet looks like this: username This is a tweet.

If I were to use variable split and a use as splitter a space how do I get to tell tasker to join %var2 %var3...%varx and leave %var1 out?

Bob Hansen

unread,
Jun 19, 2014, 11:38:21 AM6/19/14
to tas...@googlegroups.com
You can remove the first work from a variable string like this:

Variable Search [ Variable:%string Search:^([\w\-]+) Replace Matches:On <note: there is a space character after the closing parentheses ')' in the search parameter.

This will find the first word of a string and replace it with nothing (in other words - delete it) from the string. 

Brandon Horwath

unread,
Jun 19, 2014, 12:00:10 PM6/19/14
to tas...@googlegroups.com
If I were to use variable split and a use as splitter a space how do I get to tell tasker to join %var2 %var3...%varx and leave %var1 out?

Bob's method is most efficient, but since you asked...

This would be split by (optional) then action > array pop %var position: 1, next action > join %var joiner:, (a comma).

Using regex with variable search and replace is faster for tasker and more efficient though.

Message has been deleted

Mefistofelis

unread,
Jun 19, 2014, 1:52:11 PM6/19/14
to tas...@googlegroups.com
Thx both for your answers I tried the first method and it worked however I have a problem with my array and that is the following: there are some  blank spaces before each item of the array and that results in only one space being removed from the variable instead of the first word. For example my array looks like this:

ChristianaQesko Σάντσεζ: «Μπορούμε το Μουντιάλ» #CHI #wc14gr #WorldCup2014 http://t.co/37FY8kqxmu 3 minutes ago reply retweet fwd,

Zafiris_Kats Τελείωε ο αγώνας της Ισπανίας και μείναμε εμείς και εμείς για τον τρίτο αγώνα της ημέρας! #wc14gr 31 seconds ago reply retweet
 

Is there any way to remove all the spaces before the first word?

Brandon Horwath

unread,
Jun 19, 2014, 2:09:23 PM6/19/14
to tas...@googlegroups.com
I believe if you search and replace the variable for:

\s+

Check the box labeled, 'one match only' replace with: (optional)

Bob Hansen

unread,
Jun 19, 2014, 2:25:51 PM6/19/14
to tas...@googlegroups.com
To handle the leading space(s) change the Search to: ^( *[\w\-]+) <Note that there is now a space after ( as well as after the ) >
Message has been deleted

Mefistofelis

unread,
Jun 19, 2014, 3:43:37 PM6/19/14
to tas...@googlegroups.com
It worked nearly perfect, it removes the spaces but I want it to remove the blank lines between the tweets too. Could you modify it to do that too?
Many thx in advance for your help!

Bob Hansen

unread,
Jun 19, 2014, 4:32:40 PM6/19/14
to tas...@googlegroups.com
It will take a separate regex search replace action to remove blank lines. This should be done before the search replace to remove the first word. So it would look something like this.

Variable Search [ Variable:%string Search:^\s*[\r\n] Replace Matches:On ]
Variable Search [ Variable:%string Search:^([\w\-]+) Replace Matches:On ]
Reply all
Reply to author
Forward
0 new messages