Use magic text [strlen=...] applied to your source string to get its length. Then, as start index use '4 - this length' and as end index use 'this length'.View attachment 807
Hello, I would like to get the last word let's say last 4 characters of the source text that has a random characters length. I tried to use the negative sign but it says Java lang error and something, so what indexes should I use to get the last characters that I need?
I really don't know where to find this magic text I tried to use it as [strlen=[not_title]] and add the index 4,0 I also store it to a var but the var always says '[str'Use magic text [strlen=...] applied to your source string to get its length. Then, as start index use '4 - this length' and as end index use 'this length'.
you should write the [not_title] to a string variable, then you can use text manipulation - extract text action to capture the last word.I really don't know where to find this magic text I tried to use it as [strlen=[not_title]] and add the index 4,0 I also store it to a var but the var always says '[str'
I'm doing it wrong so can you show a Pic for example, much appreciated
woah it extract the characters in the [not_title] but how can I control how many char should it extract? right now it only extract last 3 letters, also thanks in advance.you should write the [not_title] to a string variable, then you can use text manipulation - extract text action to capture the last word.
"source text" should be your string variable and "text to match (regex)" should be this "\b(\w+)$" (without the quotation marks)
you can save it to a new string variable, so you can still acces the full [not_title] text in the other variable.
edit: you might actually be able to extract the last word from the notification title directly, if you put [not_title] as source text, i never tried this.
Why do you use 'Regex text to match'? It's useless as he just want to get the N last characters of a string. If the source text is the notification one, it's even simpler...you should write the [not_title] to a string variable, then you can use text manipulation - extract text action to capture the last word.
"source text" should be your string variable and "text to match (regex)" should be this "\b(\w+)$" (without the quotation marks)
you can save it to a new string variable, so you can still acces the full [not_title] text in the other variable.
edit: you might actually be able to extract the last word from the notification title directly, if you put [not_title] as source text, i never tried this.
it works but yeah it's hard to understand so I also need to know how it worksWhy do you use 'Regex text to match'? It's useless as he just want to get the N last characters of a string. If the source text is the notification one, it's even simpler...
you can't control it, this just captures the entire last word in the string. if you only want a certain amount of characters you should follow Dm114's method.woah it extract the characters in the [not_title] but how can I control how many char should it extract? right now it only extract last 3 letters, also thanks in advance.
this was one of the things he asked in his first post, if he wants only a certain amount of characters he should follow your method.Why do you use 'Regex text to match'? It's useless as he just want to get the N last characters of a string. If the source text is the notification one, it's even simpler...
This not the right way to achieve what you need (unless I misunderstood).woah it extract the characters in the [not_title] but how can I control how many char should it extract? right now it only extract last 3 letters, also thanks in advance.
where do I store [strlen=str]-4 if the integer only accepts number? there's an expression but it doesn't also accept it.This not the right way to achieve what you need (unless I misunderstood).
1⁰) if you need to extract info from notifications, use the 'Notification' trigger to get relevant magic texts
2⁰) store [not_title] or [notification] into a string variable, let's say 'str'
3⁰) store [strlen=str]-4 (or whatever number of characters you need) into an integer variable, let's say 'int'
4⁰) use substring action with 'str' as source text, 'int' as start index and [strlen=str] as end index
You can store the result either in the same 'str' variable if you don't need it anymore or in another one
After pressing button 'Expression', either type it in as indicated ([strlen=str]) or use magic texts (using the [...] submenus).where do I store [strlen=str]-4 if the integer only accepts number? there's an expression but it doesn't also accept it.
Correct. But only before an end of line (not a separator, for instance). As '.' stands for 'any kind of character' it could be useful to limitate to a set of character such as [0-9] (i.e. \d) \w.{3}$
The above regex will capture the last 3 characters from a end of line. Replace the number with whatever number you want depending on how far back you want to go.View attachment 863
Ofcourse the more info provided will yield a more pimped and polished regex. However, with the info provided I was just throwing a bone since it hadn't been mentioned.Correct. But only before an end of line (not a separator, for instance). As '.' stands for 'any kind of character' it could be useful to limitate to a set of character such as [0-9] (i.e. \d) \w
that helps, thanks for the info.Ofcourse the more info provided will yield a more pimped and polished regex. However, with the info provided I was just throwing a bone since it hadn't been mentioned.
Hey quick question the regex for 'or' function is like this ' | '
There isn't one.Hey quick question the regex for 'or' function is like this ' | '
dou you know what is for the 'and' of function?
There isn't one.
Regex by design makes the proverbial 'AND' operator implicit. It's simply not needed.