Page 10 of 13

Posted: Wed Jun 13, 2007 4:54 pm
by superdezign
Well, if you had Regex Coach, you would. :P
Just get it already.


$2 and $5 are the HTML tags.
$1, $4, and $6 is everything else.

Soo.. You preg_replace the string with $1, $4, and $6.

Posted: Wed Jun 13, 2007 6:17 pm
by ziggy3000
here's something that i have told you a long time ago...

I GOT REGEX COACH A LONG TIME AGO!!!!
THAT JUST TELLS YOU WHAT TO USE AS REGEX, NOT HOW TO USE IT

Posted: Wed Jun 13, 2007 6:23 pm
by John Cartwright
Don't get impatient with anyone Ziggy3000. :?

Posted: Wed Jun 13, 2007 6:31 pm
by ziggy3000
it's not that, i have told him a lot of times, but in every post, he says regex coach about 3 times, and tells me to get it every time.

Posted: Wed Jun 13, 2007 6:38 pm
by John Cartwright
superdezign has told you the matches you should be using, so whats the problem?

Posted: Wed Jun 13, 2007 6:41 pm
by RobertGonzalez
ziggy3000 wrote:it's not that, i have told him a lot of times, but in every post, he says regex coach about 3 times, and tells me to get it every time.
That is understandable Ziggy. But you gotta remember that he is offering his time to help you. Yes, you did say once (that I can see in reviewing this thread) that you got the Regex Coach tool. But in almost that same post you continue to ask questions about not understanding what you are doing.

Maybe it is time, since you want to learn regular expressions as bad as you say, that you go pick up a book and do some reading instead of slapping down all the suggestions that are being offered to you throughout this thread. And as a suggestion, if you wanted to learn how to handle the regular expressions needed to produce a highlighter, why haven't you downloaded a functioning app and read that? It would be a lot more helpful to you than trying to have this community repeat itself every third post in order to try to help you.

Posted: Wed Jun 13, 2007 6:42 pm
by ReDucTor

Code: Select all

$str = 'SELECT * FROM blah';
$tokens = array();
$pos = 0;
for($i=0;$e=strlen($str);$i<$e;$i++) {
  if(strpos(' .,()[]',$str{$i}) !== false) {
    $tokens[++$pos] = $str{$i};
    $pos++;
  }
  if($str{$i} == '\'') {
    for(;$i<$e;$i++) {
      if($str{$i}=='\'' && $str{$i-1} != '\\') {
        $tokens[$pos] .= $str{$i}
        break;
      }
      $tokens[$pos] .= $str{$i};
   }
    $pos++;
  }
  if($str{$i} == '"') {
    for(;$i<$e;$i++) {
      if($str{$i}=='"' && $str{$i-1} != '\\') {
        $tokens[$pos] .= $str{$i}
        break;
      }
      $tokens[$pos] .= $str{$i};
   }
    $pos++;
  }
}

$highlight = array(
'SELECT' => 'red',
'UPDATE' => 'green',
'DELETE' => 'blue'
'FROM' => 'purple',
'WHERE'=>'pink'
);

foreach($tokens as $token) {
if(isset($highlight[$token]))
print '<font color="'.$highlight[$token].'">'.$token.'</font>';
else if($token{$i} == '\'' || $token{$i} == '"')
print '<font color="orange">'.$token.'</font>';
else
print $token;
}
Yes, I know its retarded. But you know your [s]gunna[/s] going to try it, [s]coz[/s] because i didnt try it. So theres probably some mistake in it.

Posted: Wed Jun 13, 2007 7:03 pm
by superdezign
ziggy3000 wrote:here's something that i have told you a long time ago...

I GOT REGEX COACH A LONG TIME AGO!!!!
THAT JUST TELLS YOU WHAT TO USE AS REGEX, NOT HOW TO USE IT
It just makes it easier take it step-by-step. If you have it, why aren't you using it? And if you are using it, why haven't you solved your problem by now??

It seems to me as though you hadn't even tried since the last time I gave you suggestions. That doesn't mean that you haven't, but it does mean that you haven't shown any evidence that you have. If I really wanted to, I could write all of your Regex for you, but I feel that I've done too much. You say you want to learn it, so please do. Every time that I gave you code was to teach myself, but it doesn't do anything to help you learn it.

I'd really suggest you look in the Regex forum here at the "Crash Courses." I learned almost everything that I know from them. Very well-organized.

Posted: Thu Jun 14, 2007 5:51 pm
by ziggy3000
ok, i am using this for multiline comments

Code: Select all

$sql = preg_replace("'(/\*.*)(<([\w]+)>)(.*)(</\\3*>)(.*\*/)'", "<span class='comment'>$1$4$6</span>", $sql);
it still doesn't remove html tags.

Posted: Thu Jun 14, 2007 5:56 pm
by superdezign
Call a preg_match_all and output the matches. See what you get.

Posted: Fri Jun 15, 2007 3:52 pm
by ziggy3000
it's not have any matches...
Array ( )
i am trying to parse this
/* This selects a database*/
select gets highlighted blue

Posted: Fri Jun 15, 2007 3:57 pm
by ziggy3000
but when i am outputting the matches with this, it output's it correctly.

Code: Select all

preg_match_all("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $sql, $match, PREG_SET_ORDER);
i am gonna work on this part more

Posted: Fri Jun 15, 2007 4:07 pm
by ziggy3000
when i try this

Code: Select all

preg_match_all("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $sql, $match, PREG_SET_ORDER);
	foreach($match as $var){
		$tagb = $var[1];
		$text = $var[3];
		$tage = $var[4];
		$sql = str_replace($tagb.$text.$tage, $text, $sql);
	}
it removes the html tags. but when i add the comment tags to the preg_match, it doesn't work. it echos out unknown modifier "\"

Posted: Fri Jun 15, 2007 7:24 pm
by superdezign
You're probably escapint the comment characters incorrectly. What did you try?

Posted: Fri Jun 15, 2007 7:25 pm
by ziggy3000
i tried

Code: Select all

preg_match_all("/(/\*.*)(<([\w]+)[^>]*>)(.*)(<\/\\3>)(.*\*/)/", $sql, $match, PREG_SET_ORDER);