Sign in to follow this  
Followers 0

StrRegExp help

2 posts in this topic

I, unfortunatly still suck at StringRegExp. I am getting better, just very very slowly. I am trying to get as much practice as I can in, because it is a very useful and powerful tool.

I am writing a program which is going to record all of the different boards on a forum... To do this I need to extract the title of each board on the forum from its source code. Here is an example.

Source code:

<div id="content">

<div class="head"><h1>Site Suggestions</h1></div>
<div id="board_wrap">

The title of the board in this example is obviously "Site Suggestions" But I need a StringRegExp pattern that will extract it for every board.

Thanks in advance guys.

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)


try this:

$string = '<div id="content"> <div class="head"><h1>Site Suggestions</h1></div><div id="board_wrap">'

$found_A = _SRE_Between($string, '<div class="head"><h1>', '</h1></div>', 1)

If IsArray($found_A) Then
    For $i = 0 To UBound($found_A) - 1
        MsgBox(0, '', $found_A[$i])
    MsgBox(0, '', $found_A)

Func _SRE_Between($s_String, $s_Start, $s_End, $i_ReturnArray = 0); $i_ReturnArray returns an array of all found if it = 1, otherwise default returns first found
    $a_Array = StringRegExp($s_String, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If Not @error And Not $i_ReturnArray And IsArray($a_Array) Then Return $a_Array[0]
    If IsArray($a_Array) Then Return $a_Array

Only the first (for the pattern)

$string = '<div id="content"> <div class="head"><h1>Site Suggestions</h1></div><div id="board_wrap">'

$found_A = StringRegExp($string, '(?:<div class="head"><h1>)(.*?)(?:</h1></div>)', 1)

_ArrayDisplay($found_A, "")

So long,


Edited by th.meger

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

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  
Followers 0