Replacing the first occurrence in a text

Dm114

Well-known member
Unfortunately it won't work as it replaced the entire word abc|100°F instead of just 100°F. The regex matches everything before and including the first ddd°F instead of just the first ddd°F.

Eg if the string is:

abc def ghi 100°F 200°F 100°F
It would become:
xxx 200°F 100°F

Edit:
It's still doable without shell or JavaScript and I'm sure you can achieve it but it might take a longer macro. Would have been easier if Macrodroid had a replace first option too instead of replace all only.
You're right again! I was a bit in a hurry yesterday...

This time I'll be necessary to add 2 other Text Manipulations like in my original (wrong) suggestion.
 

md_sgf

Well-known member
Maybe Dm114 forgot to add $1 to "New text" field? As it works perfectly with this! 👌
Code:
$1xxx
Although don't ask me to explain how it works, esp the "(*.?)" part, as I'm not sure i know! :LOL:
 
Last edited:

Henry Puppet

New member
Maybe Dm114 forgot to add $1 to "New text" field? As it works perfectly with this! 👌
Code:
$1xxx
Although don't ask me to explain how it works, esp the "(*.?)" part, as I'm not sure i know! :LOL:
😃
Very close! The °F isn't included with $1xxx so it would need to be added ($1°Fxxx).

Using $1{lv=intTemperature}°F for the new text where intTemperature= 83

Before:
The current weather is sunny and clear with a temperature of 90°F. It feels slightly cooler at 86°F due to a light wind speed of 2 meters per hour. The air pressure is at 1015 hPa, with a relatively low humidity of 36%. The dew point is 57°F, and the...

After:
The current weather is sunny and clear with a temperature of 83°F. It feels slightly cooler at 86°F due to a light wind speed of 2 meters per hour. The air pressure is at 1015 hPa, with a relatively low humidity of 36%. The dew point is 57°F, and the visibility...

Both 86°F and 57°F remain intact even though Replace All is being used! Genius!

Would you mind posting the complete solution here so anyone else can find the solution in a single post (I'd post it but don't want to be credited for the solution)?

Thank you to everyone for looking into this.
😃
 
Last edited:

Dm114

Well-known member
😃
Very close! The °F isn't included with $1xxx so it would need to be added ($1°Fxxx).

Using $1{lv=intTemperature}°F for the new text where intTemperature= 83

Before:
The current weather is sunny and clear with a temperature of 90°F. It feels slightly cooler at 86°F due to a light wind speed of 2 meters per hour. The air pressure is at 1015 hPa, with a relatively low humidity of 36%. The dew point is 57°F, and the...

After:
The current weather is sunny and clear with a temperature of 83°F. It feels slightly cooler at 86°F due to a light wind speed of 2 meters per hour. The air pressure is at 1015 hPa, with a relatively low humidity of 36%. The dew point is 57°F, and the visibility...

Both 86°F and 57°F remain intact even though Replace All is being used! Genius!

Would you mind posting the complete solution here so anyone else can find the solution in a single post (I'd post it but don't want to be credited for the solution)?

Thank you to everyone for looking into this.
😃
Thanks to @md_sgf who corrected some of my omissions and mistakes... 😉
Screenshot_20241001_153921_MacroDroid.jpgScreenshot_20241001_153859_MacroDroid.jpg
 

Dm114

Well-known member
😃
Very close! The °F isn't included with $1xxx so it would need to be added ($1°Fxxx).
Unless the text always looks like the original one, "⁰F" in the Regex makes it more discriminant and prevents from replacing a single number not in relation with temperature. Otherwise you can remove it from the Regex.
 
Top