简体   繁体   中英

Why my sql comment parsing EReg expression not compile?

I have an sql querying tool that is written in Haxe and im trying to add some sql comment support to the code. Currently if a user has any comments (single line or multi line) the query fails on the server side. Thus, im trying to write a simple method that takes the sql the user inputs and replaces any comments with a "". Here is method

static function removeComments(snippet: SqlSnippet): SqlSnippet {

  var rComment: EReg = ~/(--[^\n]*)|(/\*[\w\W]*?(?=\*/)\*/)/;

  var resultSql = rComment.replace(snippet.sql, "");

  snippet.sql = resultSql;

  return snippet;

}

My issue isnt with this method, but that neko wont compile it. When i try to compile this method i get this message:

src/skyview/SqlSnippetParser.hx:30: character 33 : Invalid character '\\' [Finished in 0.2s with exit code 1]

the '\\' this message is refering to is the '\\' im trying to use to escape the '*' metacharacter at the beginning of the 2nd set of "()"

Does anyone know why nako wont compile the "/*" in this EReg?

The problem is not \\* . It is / needs to be escaped.

Try changing your EReg to ~/(--[^\\n]*)|(\\/\\*[\\w\\W]*?(?=\\*\\/)\\*\\/)/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM