[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  string.find(string, pattern|pattern) -- ????
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?
(New message)
Subject: string.find(string, pattern|pattern) -- ????
Your forum user name.
Register forum user name
Your forum password.
Forgotten password?
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...

Subject review (reverse sequence)

Posted by Nick Gammon   Australia  (19,672 posts)  [Biography] bio   Forum Administrator
Date Sun 17 May 2009 05:11 AM (UTC)  quote  ]
You can also use LPEG to match on patterns with more complex conditions, like this or that.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by WillFa   USA  (517 posts)  [Biography] bio
Date Sat 16 May 2009 08:06 PM (UTC)  quote  ]

Amended on Sat 16 May 2009 08:22 PM (UTC) by WillFa

Lua pattern matching isn't the same as PCRE. The rex library has all the pcre syntax you're looking for.

The simple answer to your question is "No. Use 'or' between 2 string.find calls" :)

yoda = string.find(solo, "[hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/]") 
   or string.find(solo, "www") or string.find(solo, "WWW")

Lua Pattern matching doesn't support an | as "OR", or {}s for repetition quantifiers (i.e. %w{2,3} doesn't match at least 2 but no more than 3 alpha chars.)

Lua patterns tend to run a bit faster, since they're more simplistic. The speed of the language generally matches or exceeds the speed of compiling a rex regexp.

function IsUrl (darth)
 local vader = darth:lower()
  if vader:find("^http://") or vader:find("^mailto://") 
      or vader:find("^www") then 
   return true

That should accomplish what you're looking for.
[Go to top] top

Posted by ThumpieBunnyEve   (10 posts)  [Biography] bio
Date Sat 16 May 2009 07:00 PM (UTC)  quote  ]

Amended on Sat 16 May 2009 07:02 PM (UTC) by ThumpieBunnyEve

No matter what i do in a Lua script, i cant get a pattern to include an OR.

solo = "http://ggg.cnn.com http://www.cnn.com www.cnn.com monkey-tribble-duck w.cnn.com w  ww oog.nomface.com www wwww w|www wW  W WW WWW  ouote o.ote.com.nom ___ gggg quote q.ote.com.nom.con WWWW  WWW. http://www.cnn.com"

luke = "([hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/])|([wW]+[wW]+[wW]+[\.])"

leia = "[hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/]|[wW]+[wW]+[wW]+[\.]"

r2d2 = "(([hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/])|([wW]+[wW]+[wW]+[\.]))"

c3p0 = "([hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/])*([wW]+[wW]+[wW]+[\.])*([hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/])"

jaba = "(([hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/])*([wW]+[wW]+[wW]+[\.])*([hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/]))"

boba = "[hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/]*[wW]+[wW]+[wW]+[\.]*[hHtTpPsSmMaAiIlLoO]+://[%S]*[%w#/]"

yoda = string.find(solo, luke) -- fails
yoda = string.find(solo, leia) -- fails
yoda = string.find(solo, r2d2) -- fails
yoda = string.find(solo, c3p0) -- fails
yoda = string.find(solo, jaba) -- fails
yoda = string.find(solo, boba) -- fails

I'm out of options here X_X;
There is no way to put an OR into the pattern of a string.find is there?
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.


Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]