match("^.", "ab^c");
//Result: ^c
Can anyone explain the four symbols ^ . above individually? I am quite confused of them.
thank you for your help.
match("^.", "ab^c");
//Result: ^c
Can anyone explain the four symbols ^ . above individually? I am quite confused of them.
thank you for your help.
match uses regular expressions. do a search on the web to find out more about them.
the two are confusing. the first is an escape character, which means use the character following it, as a normal character. but then the normal character (which is also a ) is used as an escape character for the ^ symbol (which is otherwise a special character - which is why it has to be escaped). and the . means search for any single character. i think...
so basically its searching for a ^ symbol, followed by any single character. and it finds ^c in the given string.
thanks, macaroniKazzo.
I just wonder why single (used as escaper for special character ^) is not enough in this expression.
then does it mean that if is used as an escaper, it has always to be two ?
bacuse you are escaping the ""s first
hmmm, i'm not sure what joojaa means...
but in this case, you have to use two, because its in quotes. if you could do this:
match ^. "ab^c";
then that would be fine, but the characters are contained inside a quoted string, and thus the (which inside a string is an escape character) escapes the next character which is another . so when the quoted string gets parsed, it becomes: ^.
which is just what you want. an escaped ^
make sense? its very confusing, I know...
just remember, if u ever have to do it yourself, just write the string out first, and THEN add the escape characters where they need to be. thats how i do it anyway.
Whanever a parser hits a qoute Pair it goes ahead and preprocesses the contents (how it actualy does this is not relevant but its safe to think thisway). Now if you want inside a pair of qoutes youd have to escape it because is a beginning start marker for escape sequence for purpose of the parser.
Now offcourse it gets parsed outside qoutes too ^ properly so if you write the "^" the match gets ^ and match parses it further internaly wich most cpmmands wont do. Thats because mach needs escapes as it actualy can convey the meaning of the symbol or the actual symbol itself (a plain ^ has a special meaning for the regexp eingene, but if somone want to actualy match it then it needs escaping).
So basicaly if you wrote print "hellon" it would be turned into a string containing real ascii values without any escape wich is the trasmitted to print.
right... so isn't that what i just said, except with a slightly more techie spin? ![]()
Yp but thats what i said too...