-2

Using regex, how can I check weather a word starts with some character, and ends with another one? For example, the word "black", how to check that it starts with "b" and ends with "k" using regex?

And can I then make a replace using "search and replace" tasker built-in feature for those two characters to be, for example, "place" instead of "black", replacing "b" with "p" and "k" with "e" respectively?

I use this in tasker program in android, to check contacts and take decision on some conditions like the one above.

Thanks in advance.

  • See the [docs](http://tasker.dinglisch.net/userguide/en/matching.html): *Regex Matching is available: 1) in the If condition of an action, when the `~R` or `!~R` operators are specified. 2) in the Variable Search Replace action 3) in the condition of a Variable Value state 4) wherever a Simple Match is possible, by preceding the regex with `~R` or `!~R`*.... *Simple Matching is used in the following places: 1) in the If condition of an action, when the `~` (match) or `!~` (not match) operators are specified. 2) in text paremeters of State and Event contexts 3) some other places :-)* – Wiktor Stribiżew Oct 16 '17 at 09:35
  • Are you sure you are using the *regex* in the right place? If yes `\bb([a-zA-Z]*)k\b` to replace with `p$1e` must work. Else, there is no way with Simple Matching. – Wiktor Stribiżew Oct 16 '17 at 09:36

1 Answers1

0

sounds like you want \sb([a-zA-Z]*)k\s

this will match b and k on the outside and make sure theres spaces around it with the \s.

[a-zA-Z]* will make sure it matches any number of characters in the alphabet.

The round brackets will save whatever it is inside it and can be retrieved by using $1 so you should be able to replace it with p$1e

Samantha
  • 751
  • 2
  • 6
  • 18