This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

I hate using regexp...

Old posts that have not been replied to for several years.
Locked
User avatar
CrazyCat
Revered One
Posts: 1359
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

I hate using regexp...

Post by CrazyCat »

Hi there, I've a little trouble using regexp.
Here's my code.

Code: Select all

proc bash:random {nick uhost handle chan args} {
	set key [http::geturl $::rand_url]
	set line [http::data $key]
	set quote [regexp -inline -all {<p class="qt">[^\f\t\v]{1,}</p>} $line]
	foreach qt [split $quote "\n"] {
		if {[string first $quote "<b>#"] > 0} {
			return
		}
		set show_quote [uncode $qt]
		if {$show_quote != ""} {
			putserv "PRIVMSG $chan :$show_quote"
		}
	}
	putserv "PRIVMSG $chan :\002End of quote\002"
}
the source code I try to parse is like this:

Code: Select all

<p class="something"><b>#1</b></p><p class="qt">here is a line<br />
and another one</p>
<p class="something"><b>#2</b></p><p class="qt">oh, a line<br />
and another one</p>
I want to obtain:
on the chan wrote:<egg> here is a line
<egg> and another one
<egg> --- Next ---
<egg> oh, a line
<egg> and another one
<egg> End of quote
and I can't because the regexp returns:
real wrote:<egg> here is a line
<egg> and another one
<egg> #2 oh, a line
<egg>and another one
<egg> End of quote
I can't succeed in finding the good way to have the regexp splitting my source in an array, or other format allowing me to have each part separated.
I know I can split on '<p class="something">' but I'm sure I can find a beautifull way with regexp...
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

if the number of lines are fix, I would suggest using neither -inline neither -all and include all matching lines into the regexp. I have regular expressions that are over 800 byte, so dont worry about it as long this is nothing called to often ^-^.

Another suggestion would be to use regsub to kill the code you dont need and split it on \n then or so.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
CrazyCat
Revered One
Posts: 1359
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Thanks, but I'd resolved it using another way (have a look to the tcl bash.tcl).
In fact, my big trouble is that I'm too used to work with PHP and it's hard to forget some tools :)
Locked