MySQL highlighter
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
what should i put in my pattern so i can make it not highlight html code because i want it to highlight the database name when someone tries to parse this
thanks superdezign!
my current code would only highlight CREATE DATABASE, but i want it to highlight COMPUTER as well, but not highlight html code. and it shouldn't depend on how long the string is. the highlighter works great though.CREATE DATABASE COMPUTER
thanks superdezign!
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
You're welcome.
And, personally, I wouldn't encourage users of the parser to use table names without quoting them, but if you want to, you can.
If you open MySQL, you can run "help" on any operation. What you are shown is the basic usage layout. Make use of it, and you should be able to do anything with those queries using regex.
And, personally, I wouldn't encourage users of the parser to use table names without quoting them, but if you want to, you can.
If you open MySQL, you can run "help" on any operation. What you are shown is the basic usage layout. Make use of it, and you should be able to do anything with those queries using regex.
nevermind, i found a really good site that teaches about regex, but i have one questions. what would i have as my regex if i want /* */ type comments?
the really good site
so far this is my pattern
the really good site
so far this is my pattern
Code: Select all
/((/\\*)(.+?)(\\*/))/- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
I don't think you need two slashes to escape the asterisk character. However, you do need to escape the '/' character because it is the delimiter. Also, I wouldn't put in so many subpatterns.
And just FYI, that regex doesn't allow for whitespace or newlines in comments, which is often why people use that style of commenting.
And just FYI, that regex doesn't allow for whitespace or newlines in comments, which is often why people use that style of commenting.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
It allows for whitespace. As for newlines, that depends on the default mode. "m" will stop at newlines, "s" will not.superdezign wrote:I don't think you need two slashes to escape the asterisk character. However, you do need to escape the '/' character because it is the delimiter. Also, I wouldn't put in so many subpatterns.
And just FYI, that regex doesn't allow for whitespace or newlines in comments, which is often why people use that style of commenting.
i got these type of comments working
i think that problem is that inside the /* and */ are spans that highlight those words. how should i make it so that it doesn't highlight that part?
but i still need help with// comment
#comment
here's my pattern/*
comment
*/
Code: Select all
$sql = preg_replace("'(\/\*(.*?)\*/|//[^<br />].*?$|\#[^<br />].*?$)'", "<span class='comment'>\\1</span>", $sql);- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm