StrSplit not splitting? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StrSplit not splitting?

Post by boiler » 17 Jan 2022, 00:43

I'm glad I was able to help. Here's how to extract that address:

Code: Select all

Clipboard =
(

Send exactly
0.00301504 BTC

to the address below:
3LMNaxe31YEH4k72F2KoHz6Bh34dqJkJ29

This address is a multisig escrow address. The site itself doesn't hold your money, they are locked in escrow. To release the funds, both you and the site have to sign the release transaction. After the contract's status is changed to paid, you will be signing the release transaction with your payment password, which only you know.
)

RegExMatch(Clipboard, "to the address below:\v+\K\V+", Address)
MsgBox, % Address

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 17 Jan 2022, 01:12

boiler wrote:
17 Jan 2022, 00:43
I'm glad I was able to help. Here's how to extract that address:

Code: Select all

Clipboard =
(

Send exactly
0.00301504 BTC

to the address below:
3LMNaxe31YEH4k72F2KoHz6Bh34dqJkJ29

This address is a multisig escrow address. The site itself doesn't hold your money, they are locked in escrow. To release the funds, both you and the site have to sign the release transaction. After the contract's status is changed to paid, you will be signing the release transaction with your payment password, which only you know.
)

RegExMatch(Clipboard, "to the address below:\v+\K\V+", Address)
MsgBox, % Address
Thank you so much! :superhappy:

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 19 Jan 2022, 19:14

boiler wrote:
17 Jan 2022, 00:43
I'm glad I was able to help. Here's how to extract that address:

Code: Select all

RegExMatch(Clipboard, "to the address below:\v+\K\V+", Address)
MsgBox, % Address
Thank you again. Now that simple line of code you just gave me is at the center of my script. The most important part of the script. So is there a way to find out how many chars are in that address variable?

I'm getting excited. The script is almost ready to launch!

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StrSplit not splitting?

Post by boiler » 19 Jan 2022, 19:34

Code: Select all

MsgBox, % StrLen(Address)

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 20 Jan 2022, 09:57

boiler wrote:
19 Jan 2022, 19:34

Code: Select all

MsgBox, % StrLen(Address)
Perfect! And thank you.
I got just a few more RegEx needs. But I think I can figure them out based on what you have given me so far.
Thanx a lot.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 29 Jan 2022, 23:43

boiler wrote:
19 Jan 2022, 19:34

Code: Select all

MsgBox, % StrLen(Address)

Grrrrr!!! Having some PITA over here. The site I am trying to work with states they work well with Chrome and Firefox. So I picked FF since I am not a big fan of anything Google. And I designed my entire script to work off of Firefox, But I was having issues with their chat system so their teckies advised me to use a different browser. No problem dude, I'll just rewrite 500 lines of my script! I got nothing better to do with my time anyways.....%$^&*(()*&^%%% :headwall:
The c&p format with Brave appears to work differently than the Firefox one. With Brave, it bunches some words together in a single substring.
So can you please tell me how to extract the number value out of the following string?
"Price: 50000"

Please and thank you boiler. I don't care about the nasty rumors, you are the best. :)

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StrSplit not splitting?

Post by boiler » 30 Jan 2022, 00:53

Code: Select all

Clipboard := "Price: 50000"
RegExMatch(Clipboard, "\d+", Price)
MsgBox, % Price

In case it can include a decimal point:

Code: Select all

Clipboard := "Price: 125.50"
RegExMatch(Clipboard, "[\d\.]+", Price)
MsgBox, % Price

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 03 Feb 2022, 23:23

boiler wrote:
17 Jan 2022, 00:43
I'm glad I was able to help. Here's how to extract that address:

Code: Select all

Clipboard =
(

Send exactly
0.00301504 BTC

to the address below:
3LMNaxe31YEH4k72F2KoHz6Bh34dqJkJ29

This address is a multisig escrow address. The site itself doesn't hold your money, they are locked in escrow. To release the funds, both you and the site have to sign the release transaction. After the contract's status is changed to paid, you will be signing the release transaction with your payment password, which only you know.
)

RegExMatch(Clipboard, "to the address below:\v+\K\V+", Address)
MsgBox, % Address
Okay, I just tried it and it doesn't work. Most likely because I changed browser so the copied test is formatted differently. All I got is a blank MsgBox.
Here is the clipboard content again:

Code: Select all

Clipboard :=
Send exactly

0.00401 BTC
To the address below:

3BhsiLqYho7z1x79eUxqh4vvJxYw3eLZLn
 
This address is a multisig escrow address. The site itself doesn't hold your money, they are locked in escrow. To release the funds, both you and the site have to sign the release transaction. After the contract's status is changed to paid, you will be signing the release transaction with your payment password, which only you know.
And I should say the long string between To the address below: and This address is a multisig escrow address. That is what I need into the variable.
Please help, boiler, You have been a savior so far.

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StrSplit not splitting?

Post by boiler » 04 Feb 2022, 00:29

The only difference is it used to show to the address below: and now it shows To the address below:, which is only one letter changing case. So just make it be case insensitive with this minor change to one line:

Code: Select all

RegExMatch(Clipboard, "i)to the address below:\v+\K\V+", Address)

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 04 Feb 2022, 20:55

boiler wrote:
04 Feb 2022, 00:29
The only difference is it used to show to the address below: and now it shows To the address below:, which is only one letter changing case. So just make it be case insensitive with this minor change to one line:

Code: Select all

RegExMatch(Clipboard, "i)to the address below:\v+\K\V+", Address)
That solved the problem!
Now on to the next RegEx, and I don't know if I am abusing of your kindness here, but I sincerely appreciate it. And my script is almost done too, about 95% of it is behind me now.
With bitcoin transactions, there is a thing called "miner fee". It's a fee we pay to the Bitcoin miners to process a transaction. This fee is dynamic, it goes up when the network is busy and it goes down when not busy. With the sort of trading I do there are two miner fees involved: the miner fee I pay to get the Bitcoin I sell into the multisig address (or escrow if ou prefer), and the miner fee the buyer pays to get it out of escrow and into his own wallet.

Now the whole point of automating my trades is so I can offer the cheapest Bitcoin price with the lowest mark up in price to a wide variety of buyers with anything from a $20 purchase to a $3000 purchase. This is a market most other traders don't want to deal with because it's just not worth the time and effort to sell $20 of Bitcoin unless they really hike up their profit margin.
This is where I come in. Since it's automated, I don't care if you want to buy $20 and I only make pennies off of it. The puter does it all while I'm watching cute cat vids on YouTube or sleeping at my work.

But I need my clients to accept to pay the miner fee from me to the escrow or order to drop my prices to a minimum even with chump change trades. So I ask a question in the chat that looks like this on the clipboard:

Code: Select all

Clipboard :=
PepeBot says: Okay so the contract price is 248 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 1.08 CAD for a total cost of 249.08 CAD. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 5:44:00 PM

My messages always start with PepeBot says: and there will always be a time stamp at the bottom of every messaage, like shown above. I want to grab the content of the next message after the one that starts with PepeBot says: and ends with (YES or NO only please)
And I would like to know how many words in his reply. The clipboard would look like this:

Code: Select all

Clipboard :=
PepeBot says: Okay so the contract price is 248 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 1.08 CAD for a total cost of 249.08 CAD. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 5:39:38 PM

His answer here.
2/4/2022, 6:05:32 PM



So in essence, I need to grad the substring His answer here. and I need to know how many words in his answer. Always between two time stamps, and always directly after (YES or NO only please)

Figuring out if he says yes or no should be easy with InStr. So I got that part covered.

Can you help, please?

Now I keep thinking I won't need your help anymore. But I will likely have one more to ask you later on. That will be the big final one where I copy the content of an email informing me the payment has been received by my bank. Out of that one. I will only need two things: the name of the payment sender, which is always in capital letters, and the amount send. But I'm not quite there just yet.

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StrSplit not splitting?

Post by boiler » 05 Feb 2022, 00:06

For future reference, I appreciate you wanting to provide some background, but the following is lot of detail that I'm taking the time to read very carefully because I think it might be important in order to give the AHK advice, and then I realize it's not, so please leave it out:
PepeLapiu wrote: Now on to the next RegEx, and I don't know if I am abusing of your kindness here, but I sincerely appreciate it. And my script is almost done too, about 95% of it is behind me now.
With bitcoin transactions, there is a thing called "miner fee". It's a fee we pay to the Bitcoin miners to process a transaction. This fee is dynamic, it goes up when the network is busy and it goes down when not busy. With the sort of trading I do there are two miner fees involved: the miner fee I pay to get the Bitcoin I sell into the multisig address (or escrow if ou prefer), and the miner fee the buyer pays to get it out of escrow and into his own wallet.

Now the whole point of automating my trades is so I can offer the cheapest Bitcoin price with the lowest mark up in price to a wide variety of buyers with anything from a $20 purchase to a $3000 purchase. This is a market most other traders don't want to deal with because it's just not worth the time and effort to sell $20 of Bitcoin unless they really hike up their profit margin.
This is where I come in. Since it's automated, I don't care if you want to buy $20 and I only make pennies off of it. The puter does it all while I'm watching cute cat vids on YouTube or sleeping at my work.



But I need my clients to accept to pay the miner fee from me to the escrow or order to drop my prices to a minimum even with chump change trades.

Regarding the rest, this does what you asked:

Code: Select all

Clipboard =
(
PepeBot says: Okay so the contract price is 248 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 1.08 CAD for a total cost of 249.08 CAD. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 5:39:38 PM

His answer here.
2/4/2022, 6:05:32 PM
)

if RegExMatch(Clipboard, "PepeBot says:\V+\(YES or NO only please\)\v+\d+/\d+/\d+, \d+:\d+:\d+ [AP]M\v+\K\V+", Answer) {
	RegExReplace(Answer, "\w+",, WordCount)
	MsgBox, % "Answer: " Answer "`nNumber of words: " WordCount
}

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 05 Feb 2022, 12:15

That is just perfect, thank you very much, sir.
I got long winded and wordy because I assumed you would be more willing to help me out if you knew what it was for. But I digress, I'll keep is short and sweet.
As I was working your code into my script, one problem occurred in my mind.
If the user answers anything other than yes or no only, I will re-ask the question until I get the yes or no. So the clipboard would look like this:

Code: Select all

Clipboard := 
PepeBot says: Okay so the contract price is 248 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 1.08 CAD for a total cost of 249.08 CAD. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 5:39:38 PM

Anything other than yes or no.
2/4/2022, 6:05:32 PM

PepeBot says: Sorry, I'm just a dumb bot, I don't undestand your answer. Please answer with only yes or no. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 6:07:38 PM

His new answer here
2/4/2022, 6:08:32 PM
So it's important the RegEx gets to look at his last reply after my last asking the yes or no question, and ignore his first Anything other than yes or no.

Because if it detects the first answer a second time, the script will keep re-asking the same "I don't understand" while not seeing the last His new answer here. Understand what I mean? It needs to be the last instance of his string after the PepeBot says: and (YES or NO only please) post, while ignoring previous instances.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 05 Feb 2022, 13:58

just to make it clear and concise. Here is the updated clipboard string:

Code: Select all

Clipboard := 
PepeBot says: Okay so the contract price is 248 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 1.08 CAD for a total cost of 249.08 CAD. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 5:39:38 PM

Anything other than yes or no.
2/4/2022, 6:05:32 PM

PepeBot says: Sorry, I'm just a dumb bot, I don't undestand your answer. Please answer with only yes or no. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 6:07:38 PM

His new answer here
2/4/2022, 6:08:32 PM
So I need to grab the His new answer here. string. It should be between two time stamps, and directly below the last post that starts with PepBot says: and ends with( YES or NO only please) while ignoring all previous instances directly after any previous PepeBot says: post. And I need to know how many words in the string.

Thank you so much!

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StrSplit not splitting?

Post by boiler » 05 Feb 2022, 14:03

Code: Select all

Clipboard =
(
PepeBot says: Okay so the contract price is 248 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 1.08 CAD for a total cost of 249.08 CAD. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 5:39:38 PM

Anything other than yes or no.
2/4/2022, 6:05:32 PM

PepeBot says: Sorry, I'm just a dumb bot, I don't undestand your answer. Please answer with only yes or no. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 6:07:38 PM

His new answer here
2/4/2022, 6:08:32 PM
)
Time := "\v+\d+/\d+/\d+, \d+:\d+:\d+ [AP]M+"
if RegExMatch(Clipboard, "PepeBot says:\V+\(YES or NO only please\)" Time "\v+\K\V+(?=" Time "\v*$)", Answer) {
	RegExReplace(Answer, "\w+",, WordCount)
	MsgBox, % "Answer: " Answer "`nNumber of words: " WordCount
}

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 05 Feb 2022, 14:06

boiler wrote:
05 Feb 2022, 14:03

Code: Select all

Clipboard =
(
PepeBot says: Okay so the contract price is 248 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 1.08 CAD for a total cost of 249.08 CAD. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 5:39:38 PM

Anything other than yes or no.
2/4/2022, 6:05:32 PM

PepeBot says: Sorry, I'm just a dumb bot, I don't undestand your answer. Please answer with only yes or no. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 6:07:38 PM

His new answer here
2/4/2022, 6:08:32 PM
)
Time := "\v+\d+/\d+/\d+, \d+:\d+:\d+ [AP]M+"
if RegExMatch(Clipboard, "PepeBot says:\V+\(YES or NO only please\)" Time "\v+\K\V+(?=" Time "\v*$)", Answer) {
	RegExReplace(Answer, "\w+",, WordCount)
	MsgBox, % "Answer: " Answer "`nNumber of words: " WordCount
}
You are a freaking god. Thank you so much. :beer:

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 05 Feb 2022, 22:06

boiler wrote:
05 Feb 2022, 14:03

Code: Select all

Clipboard =
(
PepeBot says: Okay so the contract price is 248 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 1.08 CAD for a total cost of 249.08 CAD. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 5:39:38 PM

Anything other than yes or no.
2/4/2022, 6:05:32 PM

PepeBot says: Sorry, I'm just a dumb bot, I don't undestand your answer. Please answer with only yes or no. Do you agree to pay 249.08 CAD for this trade? (YES or NO only please)
2/4/2022, 6:07:38 PM

His new answer here
2/4/2022, 6:08:32 PM
)
Time := "\v+\d+/\d+/\d+, \d+:\d+:\d+ [AP]M+"
if RegExMatch(Clipboard, "PepeBot says:\V+\(YES or NO only please\)" Time "\v+\K\V+(?=" Time "\v*$)", Answer) {
	RegExReplace(Answer, "\w+",, WordCount)
	MsgBox, % "Answer: " Answer "`nNumber of words: " WordCount
}
Well okay. I started this project thinking it was going to be relatively simple. But things just get more complicated as I get into it.
I give the buyer a minute to answer the question with yes or no. After 30 seconds I tell him I log off and will be back in 10 minutes to fetch his reply.
So far I got everything working out just fine, except in one scenario where while I log off, he answers with more than one answer like Yes than in the next post Come on! Let's do it.. In that instance, the script doesn't seem to respond at all. Can you get me something that would pull a "too many answers" into a variable? Here is what the clipboard would look like.

Code: Select all

/*
Clipboard :=
PepeBot says: Okay so the contract price is 222 CAD but to trade with me I require that the buyer (you) pay the miner fee from my wallet to the escrow. The miner fee at this time for this transaction will be 0.88 CAD for a total cost of 222.88 CAD. Do you agree to pay 222.88 CAD for this trade? (YES or NO only please)
2/5/2022, 7:32:06 PM

PepeBot says:It seems you need more time. I'll come back to check in on you in an other 5 minutes. Do you accept to pay the miner fee for this contract for a total payment of $201 CAD ? (YES or NO only please)
2/5/2022, 7:32:36 PM

Yes
2/5/2022, 7:35:55 PM

Come on! Let's do it  already.
2/5/2022, 7:35:59 PM
*/
In my testing, the script doesn't see that there was a reply at all. Can you make so that the variable Answer := "Too many replies" in this particular case? Maybe by detecting more than two timestamps after the last PepeBot says: post?

Or maybe a way to count how many timestamps after the last PepeBot says: post. I think that would work just fine,
Last edited by PepeLapiu on 05 Feb 2022, 22:12, edited 1 time in total.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 05 Feb 2022, 22:09

I don't know how easy it is for you to write this stuff. In my mind it takes you hours of research and looking into documentation, It would take me days or weeks for sure. So how long did it take you to write the 3 lines of code in your last post here?

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StrSplit not splitting?

Post by boiler » 05 Feb 2022, 22:21

Yes, it doesn't capture anything because it was specifically looking for the last response which would be immediately preceded by a PepeBot line that ends with "(YES or NO only please)" since that's the scenario you described. So now there is this other case, and if I make it specifically for this one (while also handling the original), there will be another. My goal in posting on here is to try to help people to learn to code in AHK, but to continue down this path is me becoming your personal programmer, and I don't have time for that.

To answer your last post, it took a few minutes to modify the previous pattern to work with your new case. This one would probably be a little longer since it would have to be flexible to both scenarios, so it's getting more complex, and there likely would be more. Maybe someone else would like to take up the cause. Or you might consider hiring a programmer if you are not looking to learn RegEx and related techniques yourself. This is a level or two higher than learning to write expression syntax correctly, which you've indicated is more challenging for you than I should have expected.

PepeLapiu
Posts: 324
Joined: 19 Jun 2020, 14:06

Re: StrSplit not splitting?

Post by PepeLapiu » 05 Feb 2022, 22:28

boiler wrote:
05 Feb 2022, 22:21
Yes, it doesn't capture anything because it was specifically looking for the last response which would be immediately preceded by a PepeBot line that ends with "(YES or NO only please)" since that's the scenario you described. So now there is this other case, and if I make it specifically for this one (while also handling the original), there will be another. My goal in posting on here is to try to help people to learn to code in AHK, but to continue down this path is me becoming your personal programmer, and I don't have time for that.

To answer your last post, it took a few minutes to modify the previous pattern to work with your new case. This one would probably be a little longer since it would have to be flexible to both scenarios, so it's getting more complex, and there likely would be more. Maybe someone else would like to take up the cause. Or you might consider hiring a programmer if you are not looking to learn RegEx and related techniques yourself. This is a level or two higher than learning to write expression syntax correctly, which you've indicated is more challenging for you than I should have expected.
Yes, thank you. I very much appreciate it.
Now, I don't think there needs to modify the previous code you provided. Could you please just do something that counts the number of timestamps after the last "PepeBot says:" post?
And after that I will leave you alone on this subject and either learn RegEx or find someone I can pay to do it for me....maybe you?
Would you accept a Bitcoin payment to write this last request?

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StrSplit not splitting?

Post by boiler » 05 Feb 2022, 22:37

PepeLapiu wrote: Could you please just do something that counts the number of timestamps after the last "PepeBot says:" post?
Maybe later.

PepeLapiu wrote: And after that I will leave you alone on this subject and either learn RegEx or find someone I can pay to do it for me....maybe you?
Would you accept a Bitcoin payment to write this last request?
Yes, I wouldn't even require multiple Bitcoins. I'd settle for one Bitcoin.

Post Reply

Return to “Ask for Help (v1)”