Page 7 of 13

Posted: Fri Jun 01, 2007 10:30 am
by feyd
It's a mode switch grouping. They aren't remembered like standard groups are. Basically, it's advisable to use them wherever remembering a grouping isn't important.

Forward slashes aren't escapes.

Posted: Fri Jun 01, 2007 10:35 am
by RobertGonzalez
?: is called a Non capturing Subpattern.

Posted: Fri Jun 01, 2007 11:13 am
by superdezign
Okay, so that I'm clear, (?:pattern) means that pattern must exist, but that it shouldn't be collected, right? I guess it's just for times when a character class simply won't do....?

Posted: Fri Jun 01, 2007 11:16 am
by feyd
Character classes allow an arbitrary order. Subpatterns are specific patterns which may include character classes.

Posted: Fri Jun 01, 2007 11:20 am
by superdezign
I see. :-D

I always assumed that there was at least something that regex couldn't do. They thought of everything (or, made it up as they went along).

Posted: Fri Jun 01, 2007 3:47 pm
by ziggy3000
i only semi used your code. i added the css, and some patterns, but not all of your code(makes me feel good). but i will still try to give you credit :D

@d11wtq

i tried parsing
'hello `me` '
and it worked. 8)

Posted: Fri Jun 01, 2007 4:32 pm
by ziggy3000
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
CREATE DATABASE COMPUTER
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.

thanks superdezign!

Posted: Fri Jun 01, 2007 6:33 pm
by superdezign
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.

Posted: Fri Jun 01, 2007 9:29 pm
by ziggy3000
i'm not really good at regex. how should i exclude html from the regex pattern?

Posted: Fri Jun 01, 2007 9:39 pm
by ziggy3000
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

Code: Select all

/((/\\*)(.+?)(\\*/))/

Posted: Sat Jun 02, 2007 5:11 am
by superdezign
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.

Posted: Sat Jun 02, 2007 6:48 am
by feyd
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.
It allows for whitespace. As for newlines, that depends on the default mode. "m" will stop at newlines, "s" will not.

Posted: Sat Jun 02, 2007 9:27 am
by ziggy3000
now this is my pattern
/((\/\*)(.+?)(\*\/))/s
right now, it just highights
/*
and
*/
not the stuff in the middle. help?

Posted: Sat Jun 02, 2007 10:15 am
by ziggy3000
i got these type of comments working
// comment
#comment
but i still need help with
/*
comment
*/
here's my pattern

Code: Select all

$sql = preg_replace("'(\/\*(.*?)\*/|//[^<br />].*?$|\#[^<br />].*?$)'", "<span class='comment'>\\1</span>", $sql);
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?

Posted: Sat Jun 02, 2007 10:25 am
by superdezign
Well, you'd also have to run a regex on your comments to remove HTML tags within them if you don't want double highlighting.