I need a function to set a menu item's class to active based on if a keyword is in the URL
Something like this in your theme template can work:

function MYTHEME_preprocess_menu_link(&amp;$variables) {
  if (menu_get_object()) {
    $parsed_path = explode('/', drupal_get_path_alias());
    $parsed_link = explode('/', drupal_get_path_alias($variables['element']['#href']));

    if (some_compare_func($parsed_path, $parsed_link)) {
      $variables['element']['#attributes']['class'][] ='active-trail';
    }
  }
}


You will have to implement some_compare_func yourself, or use a regular expression instead of exploding items, to do whatever matching needs to be done.

You can also check which menu the link belongs to (['#original_link']['menu_name'])

This is just a primer to get you going.