How do use the character * in RegEx, given that * is special Meta Character in RegEx. In other words how do I get following to run and print - Manish Hatwalne?
BTW, I have tried "\*" and it doesn't work. It must be simple, but somehow I am unable to find it at the moment; and not too familiar with RegEx. - Manish [ April 26, 2004: Message edited by: Manish Hatwalne ]
Originally posted by Manish Hatwalne: It should have been "\\*" or "\\Q*\\E", so it's working now!
In case someone comes along and wonders why that worked ... The "\\*" is first seen by the compiler, which uses "\" to escape special characters just like regular expressions. It interprets "\\" as "\", making the String that actually gets stuffed into your .class file "\*". Then this String is sent to the regex parser, which uses the "\" to escape the "*". Double-escaping is quite common and can get very crazy when you have languages that can interpret dynamic code created by the program itself. I remember doing a little work at c|net where they had built their own template engine. It was not uncommon to see things like exec("print(''''hello world'''')"); Absolutely insane as strings were built and passed around to be executed again and again, requiring *exactly* the correct level of nesting/escaping of quotes.