gimx Posted December 31, 2007 Share Posted December 31, 2007 (edited) Hello,I have variables in my script. The fist variable is a digit $digit which is given by user via an input. I have an array $data. Datas in array are always the same pattern : A[number]B[number] [2 numbers] (for example "A2B3 12", letters never change only numbers).Now i want to compare $digit with $data.If the first number in $data (A2B3 12) isn't the same than $digit then i don't want this data.If the first number in $data (A2B3 12) is the same than $digit, i want a new data in array for example, but i want only the the number after B and the lasts 2 numbers (A2B3 12 -> 312).I suppose i must use regex but i don't understand how i can do this script.If someone can give me an example please.Thx Edited December 31, 2007 by gimx Link to comment Share on other sites More sharing options...
Paulie Posted December 31, 2007 Share Posted December 31, 2007 I'm afraid I don't understand exactly what you are looking to do Here is the best I can give you... #include <Array.au3> $String = "A2B3 12" $Result = StringRegExp($String, "\d{1,2}",3) MsgBox(0,"",$Result) _ArrayDisplay($Result) This returns each number in the array: $Result[0] = the number after "A" $Result[1] = the number after "B" $Result[2] = the 2-digit number on the end Link to comment Share on other sites More sharing options...
gimx Posted December 31, 2007 Author Share Posted December 31, 2007 (edited) Thx for your reply.Sorry you can't understand because i have a poor english and i can't explain what i want The user have an input box where he write a number, for example 2, click OK.In my script, i get this value in a variable $digit.I have an array of datas like that :$data[0] = A2B3 12$data[1] = A1B5 09$data[2] = A3B9 15$data[3] = A2B7 03...I want to compare array with $digit.If $digit = the first number of array then insert data in new array.In my example with $digit=2, the new array is :$newdata[0] = 312 , because the first number is same than $digit (2) : $data[0] = A2B3 12$newdata[1] = 703 , for $data[3] = A2B7 03I hope it's clear... Edited December 31, 2007 by gimx Link to comment Share on other sites More sharing options...
Oldschool Posted December 31, 2007 Share Posted December 31, 2007 (edited) Thx for your reply. Sorry you can't understand because i have a poor english and i can't explain what i want The user have an input box where he write a number, for example 2, click OK. In my script, i get this value in a variable $digit. I have an array of datas like that : $data[0] = A2B3 12 $data[1] = A1B5 09 $data[2] = A3B9 15 $data[3] = A2B7 03 ... I want to compare array with $digit. If $digit = the first number of array then insert data in new array. In my example with $digit=2, the new array is : $newdata[0] = 312 , because the first number is same than $digit (2) : $data[0] = A2B3 12 $newdata[1] = 703 , for $data[3] = A2B7 03 I hope it's clear... $var = "A2" ;<==or whatever you are looking for in this array For $i = 1 to $data[0] If StringInStr($data[$i], $var) Then ;do whatever you want with it here MsgBox(0, "", $data[$i]) ExitLoop ;<==If you want to stop EndIf Next Edited December 31, 2007 by Oldschool Link to comment Share on other sites More sharing options...
gimx Posted December 31, 2007 Author Share Posted December 31, 2007 Ok thx, finally i have found a way to do it with Paulie example But your script is more simple, i try it asap Thx for your replies guys. Link to comment Share on other sites More sharing options...
gimx Posted January 1, 2008 Author Share Posted January 1, 2008 Sorry but i have another question with regex because i don't understand all switch or option. How can i test a string ? I get html code and i want some words between tag. For example, i want to see if <b>city : [string]</b> exist in the page and if it exist, i want to get the string after the word "city :". <b>city : paris</b>, i want get "paris" in a variable. Thx Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 1, 2008 Share Posted January 1, 2008 Hi, have a look at _StringBetween. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gimx Posted January 1, 2008 Author Share Posted January 1, 2008 (edited) Thx for the function, i don't know it. I try, but this function works if you know the string you search. But in my example with Paris, i don't know which town is after "city :". Paris is an example. But i think it's a good way and i try with this function PS : if someone know a good regex tutorial... Edited January 1, 2008 by gimx Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 2, 2008 Share Posted January 2, 2008 Hi, you just need the start point and end point. That's all. Learning regex is easy when you got exampes what you want to achieve. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gimx Posted January 6, 2008 Author Share Posted January 6, 2008 Sorry but my code don't work with _stringbetween.I have parse html in a variable.$var1 = "<strong><a href="http://www.blablabla.com" onclick="popUp(...);return false;"> BlaBlaBla</a></strong>"I want the link in bold but the getlink function don't work, so i try _stringbetween but don't work._StringBetween($var1, '<a href="', '" onclick=')What's wrong ?Thx Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 6, 2008 Share Posted January 6, 2008 Hi, try this pattern with StringRegExp (?<=<a href=").*?(?=") So log, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gimx Posted January 6, 2008 Author Share Posted January 6, 2008 Thx but don't work. I think i understand why the function getlink don't work, because the link is "incomplete", it's like that : <a href="/poopoopidoo/blablabla.com" onclick="popUp(...) And i think the _stringbetween don't work with several strings in start and end arguments. So... I'm with the same problem... Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 6, 2008 Share Posted January 6, 2008 (edited) Hi, post a fre examples and I'll give you a working pattern. Link --> what you want Link --> what you want Link --> what you want So long, Mega Global $str = '<strong><a href="http://www.blablabla.com" onclick="popUp(...);return false;"> BlaBlaBla</a></strong>' Global $str1 = '<a href="/poopoopidoo/blablabla.com" onclick="popUp(...)' $link = StringRegExp($str, '(?<=<a href=").*?(?=")', 1) MsgBox(64, 'Link', $link[0]) $link = StringRegExp($str1, '(?<=<a href=").*?(?=")', 1) MsgBox(64, 'Link', $link[0]) Edited January 6, 2008 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gimx Posted January 6, 2008 Author Share Posted January 6, 2008 (edited) Thx I get html code in a TD.Now, i want the link in bold : /fiche/1205/tartenpion<strong><a href="/fiche/1205/tartenpion" onclick="popUp(this.href, 'data', 'fiche', 300,300);return false;"> tartenpion</a></strong>After i can complete to add the domain like that :$url = "www.blablabla.com" & $linkBut i must get the link before Edited January 6, 2008 by gimx Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 6, 2008 Share Posted January 6, 2008 Hi, sorry I do not understand? Did my code not work for you? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gimx Posted January 6, 2008 Author Share Posted January 6, 2008 (edited) No it don't work. $html = $oTR.firstChild.nextSibling.innerHTML $link = StringRegExp($html, '(?<=<a href=").*?(?=")', 1) $url = "www.blablabla.com/" & $link[0] MsgBox(64, "test", $url) ==> Subscript used with non-Array variable.: $url = "www.blablabla.com/" & $link[0] $url = "www.blablabla.com/" & $link^ ERROR Edited January 6, 2008 by gimx Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 6, 2008 Share Posted January 6, 2008 Hi, you see that the pattern works in my test script. When $html cotains no link then $link isn't an array. You have to check that. If isarray($link) Then .... So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gimx Posted January 6, 2008 Author Share Posted January 6, 2008 Ok thx Link to comment Share on other sites More sharing options...
gimx Posted January 12, 2008 Author Share Posted January 12, 2008 Sorry but i have another question. I have this string : 2c3f5e(2568)8f4e1a I want only strings like that number+letter. In the example, the result must be 2c 3f 5e 8f 4e 1a. Wich pattern can i use plz ? I use : (([0-9][a-z])*) but it don't work. Thx Link to comment Share on other sites More sharing options...
Paulie Posted January 12, 2008 Share Posted January 12, 2008 Like this? #include <array.au3> $String="2c3f5e(2568)8f4e1a" $Result=StringRegExp($String,"([0-9][a-z])+?",3) _ArrayDisplay($Result) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now