# One more regex problem!

**URL:** https://forum.kirupa.com/t/one-more-regex-problem/189711
**Category:** Uncategorized
**Created:** [June 5, 2006, 3:49pm UTC](https://forum.kirupa.com/t/one-more-regex-problem/189711 "2006-06-05T15:49:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![logikal2](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/logikal2/32/1143_2.png) [@logikal2](https://forum.kirupa.com/u/logikal2)
#### Post date: [June 5, 2006, 3:49pm UTC](https://forum.kirupa.com/t/one-more-regex-problem/189711/1 "2006-06-05T15:49:32Z")

</div>

Hey again!

This time, my goal is to create a syntax highlighter using PHP. Here’s the deal: I have an array with every keyword used in Actionscript.

Here’s an example:

```php
$KEYWORDS=array("goto","gotoAndPlay","trace");

```

-----replaces keyword with highlighted-----

```php
for($i=0;$i<count($KEYWORDS);$i++) {
  $str = str_replace_callback("???","highlight",$str);
}

```

------this returns the colored code-----

```php
function highlight($m) {
  $code = "<font color='#0099FF'.>".$m[1]."</font.>";
  return $code;
}

```

I figured that the best way to implement this was just to say "if the word in question doesn’t have any alphanumeric (AZaz09) directly to the right or left of it, then it counts.

How do you write that expression in Regex? That includes importing the array value ($KEYWORDS[$i]) dynamically into Regex.

Anyone who solves this one is my hero.
