Regex expression

Post your questions and help other users.

Moderator: Martin

Post Reply
robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Regex expression

Post by robchoc » 03 Dec 2018 11:02

I'm trying to write a script that will automate this number captcha but I'm stuck with the Regex expression that I need to use.

I need to get the first number into my first variable and the second number into my second variable.


Debug dialog show this:

press 24, 32 (can also be single numbers like 3, 22 or 3, 5 or 12, 4)
1
2
3
4
5
and so on...

Image


The rest seems fairly simple as I would put the first number into no1 variable and the second into no2.
I would then click no1 and then no2.

Thanks

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Regex expression

Post by anuraag » 03 Dec 2018 12:11

I dont understand what you want?
You need regex for "press 24,32"?
Or you want Variable1=24 and Variable2=32

robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Re: Regex expression

Post by robchoc » 03 Dec 2018 12:31

What I'm trying to do is get the first number into Variable1 and the second number into Variable 2

Possible combinations of numbers are:
press ?, ?
press ?, ??
press ??, ?
press ??, ??

I need the regex expression to get the numbers. Or maybe there is another way.


This is an example of the debug string that I have to work with:

press 24, 32
1
2
3
4
and so on upto 36

So if you had to get the numbers into 2 different variables, how would you do it?

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Regex expression

Post by anuraag » 03 Dec 2018 12:58

So you need to first grab press ??, ?? from your string. If i am not wrong it looks like

Code: Select all

press + space + number + comma + space + number
Your string looks like
press 24, 32
1
2
3
4

So this will give you press ??, ??

Code: Select all

output=findAll("string", 'press\\s\\d+,\\s\\d+')
Then

Code: Select all

var=findAll(output, '\\d+')
var[0] will give first number
var[1] will give second number

robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Re: Regex expression

Post by robchoc » 03 Dec 2018 16:02

Got it working, many thanks.

robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Re: Regex expression

Post by robchoc » 03 Dec 2018 16:51

I have another issue and that is when my screen does not show the captcha.

The screen with the captcha pops up occasionally and I only want my script to run when it does otherwise it throws up an error invalid index 0.

I have the following in my script:

Code: Select all


**
**
**
text=getTextInActiveWindow();
sleep (2000);
output=findAll({text}, 'press\\s\\d+,\\s\\d+');
var=findAll(output, '\\d+');
click(var[0]);
sleep (500);
click(var[1]);
**
**
**
It's fine when I have the captcha but when it does not have one it stops working.

What is the best way to only run this part of the script if the captcha pops up?

Thanks.

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Regex expression

Post by anuraag » 03 Dec 2018 17:06

Use condition while or if
While will loop untill that dialogue appears.
If will check only once

Code: Select all

while (!existsElementById("android:id/button1"))
{sleep(100)
}
Your script

Code: Select all

if (existsElementById("android:id/button1"))
{your script
}
You need to find element id by using overlay control helper.

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Regex expression

Post by anuraag » 03 Dec 2018 17:14

You can also replace existsElementById with other like getText or getTextById.

Edit : here @Desmanto shown how to use condition.
http://automagic4android.com/forum/view ... 825#p22825

robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Re: Regex expression

Post by robchoc » 03 Dec 2018 17:32

Perfect I went for the if with {}

Many thanks

Post Reply