Thread Tools Display Modes
04-15-07, 04:49 PM   #1
Vraxi
A Defias Bandit
Join Date: Apr 2007
Posts: 2
Disable magic characters in pattern

Hiya people
Im kinda new to LUA so might be a silly question....
But i got problems with the magic characters in patterns.
Is there some way i can disable these magic characters?

So the line: string.find("DoH!?!","DoH...") would return false?

I only want the string.find(arg1, arg2) to return true if arg1 contain arg2 exactly (no use of magic characters)

Both "DoH!?!" and "DoH..." have been entered by a user so demanding the user to type "DoH!%?!" and "DoH%.%.%." is not a solution



Vraxi
  Reply With Quote
04-15-07, 05:13 PM   #2
DarkT
A Defias Bandit
 
DarkT's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 2
Code:
string.find(arg1, arg2, 1, true)
The 3rd argument specifies where to start the search (1 is default), and the 4th specifies whether or not pattern matching facilities should be turned off (false is default), so setting it to true will just do a regular plain "find substring" operation.
  Reply With Quote
04-16-07, 07:07 AM   #3
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Originally Posted by DarkT
Code:
string.find(arg1, arg2, 1, true)
The 3rd argument specifies where to start the search (1 is default), and the 4th specifies whether or not pattern matching facilities should be turned off (false is default), so setting it to true will just do a regular plain "find substring" operation.
What would happen if you wanted to do pattern matching but needed to use that character?

Vraxi: You need to escape the . characters. You can do this with a % sign. What you would want, for your above expression:

string.find("DoH!?!","DoH%.%.%.")

And as you see:

Code:
> a = "DoH!?!";
> return string.find(a, "DoH...");
1       6
> return string.find(a, "DoH%.%.%.");
nil
> a = "DoH...";
> return string.find(a, "DoH%.%.%.");
1       6
(Btw, string.find returns nil, not false, when it doesn't match. Slight but important difference)


Good luck
-- Shirik
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
04-16-07, 10:09 AM   #4
Vraxi
A Defias Bandit
Join Date: Apr 2007
Posts: 2
Many many thanks!!
It works perfectly now

(Btw, string.find returns nil, not false, when it doesn't match. Slight but important difference)
True true your right... i just forgot >.<

Vraxi
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Disable magic characters in pattern


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off