Need regex lesson
Posted: Mon Dec 29, 2014 10:32 pm
I gave this the other day as an example of how to replace any number or length of strings of "/" with "//":
So if you had:
"a/a//a///a//////////////a"
You would get "a//a//a//a//a". Works like a charm.
But I all of a sudden do not understand my own gadget. In other words, if I am running this handler on, say, "a/a/", shouldn't I get: "a//". The function should match the wildcard string "/...../" (the string fragment "/a/", char 2 to 4) and return "//" in its place. That is, the first "a" appended to "//". At least that is how I read the explanation of the wildcard "*" in the dictionary entry of the "filter" command. Is replaceText different? I doubt it.
Mr Thierry?
Craig Newman
EDIT, I had thought that the "/" character itself was an issue, since it is an escape char in PCRE expressions, but it makes no difference if you substitute, say, "x". "AxAxxAxxxxxxxA" yields "AxxAxxAxxA".
Code: Select all
on mouseUp
put replaceText(fld 3,"/*/","//") into fld 4
end mouseUp
"a/a//a///a//////////////a"
You would get "a//a//a//a//a". Works like a charm.
But I all of a sudden do not understand my own gadget. In other words, if I am running this handler on, say, "a/a/", shouldn't I get: "a//". The function should match the wildcard string "/...../" (the string fragment "/a/", char 2 to 4) and return "//" in its place. That is, the first "a" appended to "//". At least that is how I read the explanation of the wildcard "*" in the dictionary entry of the "filter" command. Is replaceText different? I doubt it.
Mr Thierry?
Craig Newman
EDIT, I had thought that the "/" character itself was an issue, since it is an escape char in PCRE expressions, but it makes no difference if you substitute, say, "x". "AxAxxAxxxxxxxA" yields "AxxAxxAxxA".