Help with RegExp library for PB
Posted: Fri Mar 10, 2006 1:55 am
I'm trying to use regular expression to parse HTML file.
I've did some tests with the RegExp Library for PB from 'FloHimself' found at the link below:
http://www.purearea.net/pb/english/userlibs.php
The expression <HTML\b[^>]*> should match the tag <HTML> in:
<HTML><HEAD><TITLE>PureBasic : ...i/TITLE></HEAD><BODY></BODY></HTML>
I want to remove the tag.
This is the code i've tried
It doesn't work.
I don't understand the second argument in the RegSub() function ("\2").
From the help file it says:
Here's a link to test regular expression:
http://www.javaregex.com/test.html
I've did some tests with the RegExp Library for PB from 'FloHimself' found at the link below:
http://www.purearea.net/pb/english/userlibs.php
The expression <HTML\b[^>]*> should match the tag <HTML> in:
<HTML><HEAD><TITLE>PureBasic : ...i/TITLE></HEAD><BODY></BODY></HTML>
I want to remove the tag.
This is the code i've tried
Code: Select all
; Simple example on using the RegExp PureBasic library
; FloHimself (FloHimself@web.de) - Oct 14, 2003
;*Reg = RegComp ("(<TITLE>|<title>)(.*)(</TITLE>|</title>)") ; compiles a regular expression
*Reg = RegComp ("<HTML\b[^>]*>") ; compiles a regular expression
Html$ = "<HTML><HEAD><TITLE>PureBasic : visual basic compiler, easy & optimized basic programming language, basic, compiler</TITLE></HEAD><BODY></BODY></HTML>"
RegExec(*Reg, Html$) ; Returns 1 for success (match) and 0 for failure (no match)
Title$ = Space(500) ; Size destination buffer to store substitution
RegSub(*Reg, "\2", Title$) ; Copy substitution to destination buffer
Debug Title$
I don't understand the second argument in the RegSub() function ("\2").
From the help file it says:
Anybody got any luck with that library??RegSub()
Syntax
RegSub(*Reg, Source$, Dest$)
Description
RegSub(*Reg, Source$, Dest$) copies Source$ to Dest$, making substitutions according to the most recent regexec performed using *Reg. Size the Dest$ buffer large enough to store the substitution, otherwise a runtime error may occur!
Each instance of '&' in Source$ is replaced by the substring. Each instance of '\n', where n is a digit, is replaced by a stored substring. To get a literal '&' or '\n' into Dest$, prefix it with \; to get a literal \ preceding '&' or \n, prefix it with another \.
Here's a link to test regular expression:
http://www.javaregex.com/test.html