PDA

View Full Version : Does SUF 8 support pattern matching ?



igangang
12-04-2009, 07:47 AM
I've noticed some post telling pattern matching is supported in AMS. I think it should also supported in the SUF 8. But it seems no.:huh


-- Set the string content.
str = "http://www.pb.com/s?wd={searchTerms}&im=fufu_yu&ie=utf-8"

-- Check whether it is of www.pb.com.
isExist = String.Find(str, "www.pb.com", 1, false);
if isExist ~= -1 then
-- If it is from www.pb.com, replace &im=fufu_yu with &op=food.
new_content = String.Replace(str, "&im=[%w_]+", "&op=food", false);
-- Write the result into result.txt in C drive.
TextFile.WriteFromString("C:\\result.txt", new_content.."\r\n", true);
end

The result.txt produced in the C drive contains "http://www.pb.com/s?wd={searchTerms}&im=fufu_yu&ie=utf-8". It seems SUF 8 doesn't support pattern matching or I miss something?:wow

pww
12-04-2009, 10:17 AM
LUA supports this, see docs for string.match(), string.gsub() etc.(note the lower case). Although these functions are not officially supported in SF, everything I used so far works just fine.

igangang
12-04-2009, 08:14 PM
Thank you pww for reply.
According to your suggestion

LUA supports this, see docs for string.match(), string.gsub() etc.(note the lower case). Although these functions are not officially supported in SF, everything I used so far works just fine.

I tried to use string.replace (in lower case),but it prompts and error.
http://i50.tinypic.com/34nlbmf.jpg
It seems that SUFdoesn't recognise string.replace (in lower case) as an action command. Maybe I still miss something? I also tried string.match, but it prompts similarly.
It will be great help if you could modify my code and post it here.
:cool

pww
12-05-2009, 12:57 AM
that's because there is no string.replace in LUA, use string.gsub()



myStr = string.gsub(string, pattern, replacement [, number of replacements]);


http://www.lua.org/manual/5.1/manual.html

BTW you can achieve what you want with built-in SF functions, for example find the position of "im=fufu" in the string using String.Find, cut the string up to there with String.Left, then append "&op=food" to the result.

igangang
12-05-2009, 07:13 PM
Thanks pww.
You really helped me understand how to use pattern in SUF. I've been using PCRE for some time so ve been used to regex. You makes me able to use regex knowlege in IR products.:yes
Maybe I should spend some time on lua manual;)

I also found this page to be helpful in string pattern match:

http://lua-users.org/wiki/StringLibraryTutorial

Hope to help the others who want to use pattern match.

jassing
12-05-2009, 11:01 PM
I tried to use string.replace (in lower case),but it prompts and error.

To add to what was said "there is no string.replace" -- there is a String.Replace() in IndigoRose "lua".

LUA has it's own set of functions and objects. IndigoRose has it's own; sometimes they overlap; in which case, the lua version won't work.

IR has Math.Mod() but LUA uses %; you can't use % in IR's products.

Learning LUA has a HUGE advantage over just using what IR gives you; although; it does get in the way sometimes, as you have to remember "String" is not the same as "string". If it starts with a capital letter, it's an IndigoRose object/command. If not; it's native LUA.

hope that helps a bit...

igangang
12-06-2009, 01:57 AM
Thank you jassing for your addition. This really help me understand deeper.



LUA has it's own set of functions and objects. IndigoRose has it's own; sometimes they overlap; in which case, the lua version won't work.

IR has Math.Mod() but LUA uses %; you can't use % in IR's products.


I tried String.Find and string.find in my code. They all work. But the "IR's find" doesn't support pattern matching.
So I assume that if I want to use pattern matching, I should use LUA style.
And sometimes LUA and IR hold the same functions in different names such as Math.Mod() and %, String.Replace and string.gsub



Learning LUA has a HUGE advantage over just using what IR gives you; although; it does get in the way sometimes, as you have to remember "String" is not the same as "string". If it starts with a capital letter, it's an IndigoRose object/command. If not; it's native LUA.


You really encouraged me! I will add LUA to my IR requirements.:lol