I’m studing this topic and I met problem to understand this example…
rexCompile("\\([a-z]+\\)\\.\\1") => t
rexExecute("abc.bc") => t
rexExecute("abc.ab") => nil
It is not clear why the second case is nil and if I type:
rexSubstitute( “debug: \\0" ) => debug: bc.bc
Why the result is bc.bc?
\1 register should not point to abc?
Please, could you clarify me how it works? Where could I find accurate information as the cdsdoc is not clear on how registers work.
Giuseppe,Looks like a bug. I don't think rexExecute("abc.bc") should return t either. Only "abc.abc" should return t.What seems to be happening is that \1 is incorrectly being stored as "bc", and that's why the first case returns t.You should contact customer support about this.Note that in IC61 you have the "pcre" functions which provide access to a [u]much [/u] more powerful regular expression parser/compiler etc - so I'd take a look at that.Regards,Andrew.
Hi Giuseppe,It looks correct to me. Your first expression:rexCompile("\\([a-z]+\\)\\.\\1") ; => tstand for :" search any pattern that match 'blablablaXXXX.XXXX'So if you enter 'abc.bc' the parser catch :'bc.bc' as XXXX.XXXXEverything is fine.Regards,Remarks : 'blablablaXXXXblabla.XXXX' is not caught by rexCompile("\\([a-z]+\\)\\.\\1")
Good point. I agree. This should work. In general it tries to match the whole pattern, not each bit in turn.So I agree. It's behaving correctly.Andrew.
Ok, perhaps I do not understand how it works...rexCompile("\\([a-z]+\\)\\.\\1") ; => tok,If I do rexExecute("abc.bc")\1 should contain the value matched by \([a-z]+)\, ok? In our case it should be "abc". It is correct?I would expect our rexCompile should be equivalent to rexCompile("[a-z]+\\.abc")so rexExecute("abc.bc") => nilandrexExecute("abc.ab") => nilWhy the first is true??>>stand for :" search any pattern that match 'blablablaXXXX.XXXX'Could you explain hot to interpret rexCompile("\\([a-z]+\\)\\.\\1") ?Thank you,Giuseppe
In the first case, you're expecting that the \([a-z]+\) matching happens in isolation. It doesn't. What happens is that it tries to match the entire pattern, and so it will be looking for a combination of 1 or more a-z characters. followed by ".", followed by exactly the same combination. Since it can successfully do that if the \1 part ends up as "bc", then it will do that. If you'd have anchored the pattern:rexCompile("^\\([a-z]+\\)\\.\\1")then this would have forced it to match the complete sequence of characters before the ".", in which case only "abc.abc" would have matched.So as was stated previously, you're matching:blablahblaXXXX.XXXXwhere XXXX is a variable length sequence of a-z - but is the [u]same[/u] either side of the dot.Regards,Andrew.