Jump to content
Sign in to follow this  
Allow2010

RegEx help

Recommended Posts

Allow2010

hi,

i need to find in html source the selected value from this

<select id="uiViewDownTime" name="down_time_value" onchange="" size="1">
<option value="15" >15 Minuten</option>

<option value="30" selected="selected">30 Minuten</option>
<option value="45" >45 Minuten</option>
<option value="60" >60 Minuten</option>
<option value="90" >90 Minuten</option>
<option value="120" > 2 Stunden</option>
<option value="180" > 3 Stunden</option>
<option value="240" > 4 Stunden</option>

<option value="300" > 5 Stunden</option>
<option value="360" > 6 Stunden</option>
<option value="480" > 8 Stunden</option>
<option value="600" >10 Stunden</option>
<option value="720" >12 Stunden</option>
<option value="900" >15 Stunden</option>
<option value="1080" >18 Stunden</option>

<option value="1260" >21 Stunden</option>

</select>

I have this php code which does the trick,

preg_match('@name="down_time_value".*?<option value="(\d+)"[^>]+?selected.*?</select>@s', $output, $matches);

but i can not get it working in autoit with StringRegExp.

Can some RegExp professional please help me out (and if possible even explain it, so i can learn a bit:-))

Thanks in advance!

Share this post


Link to post
Share on other sites
Melba23

Allow2010,

Certainly not a "RegExp professional", but this works for me: :oops:

$sHTML = '<select id="uiViewDownTime" name="down_time_value" onchange="" size="1">' & @CRLF & _
            '<option value="15" >15 Minuten</option>' & @CRLF & _
            '' & @CRLF & _
            '<option value="30" selected="selected">30 Minuten</option>' & @CRLF & _
            '<option value="45" >45 Minuten</option>' & @CRLF & _
            '<option value="60" >60 Minuten</option>' & @CRLF & _
            '<option value="90" >90 Minuten</option>' & @CRLF & _
            '<option value="120" > 2 Stunden</option>' & @CRLF & _
            '<option value="180" > 3 Stunden</option>' & @CRLF & _
            '<option value="240" > 4 Stunden</option>' & @CRLF & _
            '' & @CRLF & _
            '<option value="300" > 5 Stunden</option>' & @CRLF & _
            '<option value="360" > 6 Stunden</option>' & @CRLF & _
            '<option value="480" > 8 Stunden</option>'

$aRet = StringRegExp($sHTML, '(d+)"ssel', 3)

MsgBox(0, "Result", $aRet[0])

Translation:

(d+)   - Capture a string of digits
"ssel  - followed by a double quote, a space, and the string "sel"

3       - Return an array of what was found

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Allow2010

Thank you for your help....

it work fine, but i should have mentioned that the above html is only part of a bigger html page and there may be other lines that contain "selected"

thats why there is a bit more regex vodoo in the original line:-)

Share this post


Link to post
Share on other sites
Melba23

Allow2010,

but i should have mentioned that the above html is only part of a bigger html page and there may be other lines that contain "selected"

Quite so - then I would not have wasted my time posting the above :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Allow2010

my aplogies...

Share this post


Link to post
Share on other sites
GEOSoft

change m23s expression to use the flag 4 instead of 3 and see if that gives you what you want. it should be a php compatable array of arrays.

Using the toolkit in my signature should allow you to load the page on the 'load web page' as html and test it in there. just make sure you select the 4 flag. you could even run a couple of tests using each of the flags to get used to how they work in pcre.

tip; since the help file was never finished, hover over any of the controls and look at the status bar to see what they do.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Allow2010

Thanks, for the infos, i will try...

Share this post


Link to post
Share on other sites
Allow2010

I got all my regex working fine so far, but the one above still drives me mad...

Can anyone tell me what the @ at he beginning and the "@s" in this regex means? I beleive it is something only valid in php...

preg_match('@name="down_time_value".*?<option value="(d+)"[^>]+?selected.*?</select>@s', $output, $matches);

Help please, i did a lot of reading, just can't find out this one:-)

Edited by Allow2010

Share this post


Link to post
Share on other sites
jchd

Lookup a php tutorial. My wild guess is that @name and @s are variable interpolation (get replaced by variables values at runtime. But I've been proved wild-guessing wrong before, so have your salt handy.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Allow2010

thanks...have reading up several manuals...none mentions @ :-(

Share this post


Link to post
Share on other sites
GEOSoft

you will probably have more luck looking for that symbol in a php manual.

in php it means 'suppress errors'

why it would be used in a regex beats me though.

There is a brief description here

or try this google results page


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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
Sign in to follow this  

×