Question: As part of a project, I need to analyse string which may contain a reference to PHP in the following manner:

`[php]functionName(args1, args2)[/php]`

The function name is not always the same, and I would like to replace everything in the above example (including the pseudo-tags) with another value. 

Can anyone suggest a Regular Expression to effectively match the pattern `[php]anything[/php]`. 

Sorry if this is a basic question, but I suck at Regular Expressions!

Answer: 
```
<?php

$s = "Lorem ipsum dolor sit amet, [php]functionName(args1, args2)[/php] ok.";

echo preg_replace("/\[php\][^\[]+\[\/php\]/", "seems to work", $s) . "\n";

// prints => Lorem ipsum dolor sit amet, seems to work ok.

?>

```
Try this:

```
$start_tag ='\\\\[php\\\\]\\\\s*';
$function  ='((\\\\w+)\\\\s*\\\\(([^)]*)\\\\)';
$end_tag   ='\\\\s*\\\\[\\\\/php\\\\]';

$re='/(' . $start_tag . $function . $end_tag . ')/';

```

which is:

```
(                 # start capture group #1 - full match
\[                # literal '['
php               # literal 'php'
\]                # literal ']'
\s*               # optional whitespace
(                 # start capture group #2 - full function
  (               # start capture group #3 - function name
    \w+           # one or more word chars [A-Za-z0-9_]
  )               # end capture group #3
  \(              # literal '('
    (             # start capture group #4 - function arguments
      [^)]*       # zero or more non-')' chars
    )             # end capture group #4
  \)              # literal ')'
)                 # end capture group #2
\s*               # optional whitespace
\[                # literal '['
php               # literal 'php'
\]                # literal ']'
)                 # end capture group #1

```