Regex expression
Moderator: Martin
Regex expression
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...
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
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...
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
Re: Regex expression
I dont understand what you want?
You need regex for "press 24,32"?
Or you want Variable1=24 and Variable2=32
You need regex for "press 24,32"?
Or you want Variable1=24 and Variable2=32
Re: Regex expression
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?
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?
Re: Regex expression
So you need to first grab press ??, ?? from your string. If i am not wrong it looks like
Your string looks like
press 24, 32
1
2
3
4
So this will give you press ??, ??
Then
var[0] will give first number
var[1] will give second number
Code: Select all
press + space + number + comma + space + number
press 24, 32
1
2
3
4
So this will give you press ??, ??
Code: Select all
output=findAll("string", 'press\\s\\d+,\\s\\d+')
Code: Select all
var=findAll(output, '\\d+')
var[1] will give second number
Re: Regex expression
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:
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.
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]);
**
**
**
What is the best way to only run this part of the script if the captcha pops up?
Thanks.
Re: Regex expression
Use condition while or if
While will loop untill that dialogue appears.
If will check only once
You need to find element id by using overlay control helper.
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
}
Re: Regex expression
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
Edit : here @Desmanto shown how to use condition.
http://automagic4android.com/forum/view ... 825#p22825
Re: Regex expression
Perfect I went for the if with {}
Many thanks
Many thanks