Regex delimiter

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
frodo baggins
Posts: 2
Joined: Wed Aug 19, 2009 3:26 pm

Regex delimiter

Post by frodo baggins » Wed Aug 19, 2009 3:39 pm

hello everybody

this is my first experience with runrev and so far it has been kinda like a roller coaster ride, one moment i'm awestruck , the next moment i'm almost scratching my head uncontrollably.

anyway what is the regex delimiter?

i have this regex matchtext("<h1 ="(.*?)">" ,matchedtext) and i tried \ as the delimiter but i got an error

i'd appreciate help in this

pardon my grammar, i'm in a bit of a hurry.

dablock
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 23
Joined: Wed Apr 23, 2008 2:51 pm

Post by dablock » Wed Aug 19, 2009 4:20 pm

I know what you mean, Frodo. Many things are amazingly easy then something seemingly simply is confounding.

You're using the correct literal character, "\". This works for me.

Code: Select all

on mouseUp
   put "<a href=" & quote & "http://forums.runrev.com" & quote & ">RunRev Forum</a>" into tUrl
   get matchText ( tUrl, "<a href=\"(.*?)\">", tMatchedText)
   put tMatchedText
end mouseUp
This displays

Code: Select all

http://forums.runrev.com

frodo baggins
Posts: 2
Joined: Wed Aug 19, 2009 3:26 pm

Post by frodo baggins » Thu Aug 20, 2009 3:27 am

dablock wrote:I know what you mean, Frodo. Many things are amazingly easy then something seemingly simply is confounding.

You're using the correct literal character, "". This works for me.

Code: Select all

on mouseUp
   put "<a href=" & quote & "http://forums.runrev.com" & quote & ">RunRev Forum</a>" into tUrl
   get matchText ( tUrl, "<a href="(.*?)">", tMatchedText)
   put tMatchedText
end mouseUp
This displays

Code: Select all

http://forums.runrev.com
Thanks a lot dablock, your code worked.

i had not added the command 'Get' before matchtext and hence the error :oops:

just one last question,

is there a way to get all the matches of a pattern into an array or something and then iterate over the them and print it?

I tried doing so but the variable got only the first match!

Also, Is there some sort of foreign function interface to c/c++ or some other language in runrev? I'm thinking of creating a pcre compatible regex package with named captures and all that if there is an ffi interface. The present regex library falls short on many counts in my opinion.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Thu Aug 20, 2009 6:03 am

There *is* an externals api, but it's about to get a major revision, so you'd probably want to wait until after the conference to get started on this.

Post Reply