youtuber

Random StringRegExp Question

4 posts in this topic

How do I find a number of variables random

$test0 = "yılınız: 0"
$test1 = "yılınız: 1"
$testrand = Random($test0,$test1)
$year = StringRegExp($testrand, '(?i)z:\s(\d+)(.*?)', 3)

if not $year=1 then
      Msgbox(0, "Target", "test 0: " & $year)

Else
      Msgbox(0, "Target", "test 1: " & $year)

EndIf

 

Share this post


Link to post
Share on other sites



hi

i have find multiple problem :

 - your usage of random seems bad.

 - StringRegExp return a array, so u need use $aYear[0]

#include <Array.au3>; for _ArrayDisplay

$sStart = "yılınız: "
$iRandom = Random(1950, 2050, 1); return 1950-2050 integer
$sString = $sStart & $iRandom

; Return "(.*?)" in a array
$aYear = StringRegExp($sString, '(?i)z:\s(\d+)(.*?)', $STR_REGEXPARRAYGLOBALMATCH)

If @error then
    Msgbox(0, "$iRandom=" & $iRandom, "Year not found")
Else
    Msgbox(0, "$iRandom=" & $iRandom, "Year found : " & $aYear[0])
EndIf

;_ArrayDisplay($aYear); for help to understand

 

1 person likes this

Share this post


Link to post
Share on other sites
$test0 = "yılınız: 0"
$test1 = "yılınız: 1"
$testrand = Random(0, 1 , 1)
$testrand = eval("test" & $testrand)
msgbox(0, "Target" , $testrand)

 

1 person likes this

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Use an array :

Local $aTest = ["yılınız: 0", "yılınız: 1"]

$testrand = $aTest[ Random(0, UBound($aTest) - 1 , 1) ]
$year = StringRegExp($testrand, '\d+$', 1)
If @error Then Exit MsgBox(16, "", "invalid string")

MsgBox(0, "", $year[0])

 

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now