Add an attribute to a specific tag in text body of page I would like to add an attribute to a specific tag in the text body of a page. 

I was thinking in this direction:


add MYTHEME_preprocess_field(&amp;$variables) to template.php
apply regular expression to the right field (but which one? $variables['items'][0]['safe_value']?)


Can anyone give me a specific working example of applying a regular expression to the body field of a page?

Thanks!
Since you are just looking to add an attribute to a tag, you could do your changes to the field #markup instead. A simple example:

/**
 * Implements template_preprocess_field().
 */
function MYTHEME_preprocess_field(&amp;$variables) {
  if ($variables['element']['#field_name'] == 'body') {
    $markup = preg_replace('/href=/', 'title="foo" href=', $variables['items']['0']['#markup']);
    $variables['items']['0']['#markup'] = $markup;
  }
}