Regular expression problem

Hello

I have this string

$output=“Jan-19-12 03:11:31 [Various_Words] 85.54.177.0 – invalid HELO: ‘PC100521998230’”;

I need to remove from $output [Various_Words] to have this

$output=“Jan-19-12 03:11:31 85.54.177.0 – invalid HELO: ‘PC100521998230’”;

Into the brackets there could be various words not only Various_Words .

I am trying this

$pattern = ‘/ \[\[A-Za-z]\]/’ ;
$replacement =’ ';
$output = preg_replace($pattern, $replacement, $output) ;

but the pattern is not good, any help please ?

Thank you

This will do the trick. It matches the parts of the $output that you want to keep and puts it in to a variable.

<?php

$output = "Jan-19-12 03:11:31 [Various_Words] 85.54.177.0 -- invalid HELO: 'PC100521998230'";
$regex = "#^([a-z]{3}\\-\\d{2}\\-\\d{2} \\d{2}:\\d{2}:\\d{2}) .+ (\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3} \\-\\- invalid HELO: '.+')$#Ui";

preg_match($regex, $output, $match);

if(count($match) == 3)
{
	$desired_output = $match[1].' '.$match[2];
	var_dump($desired_output);
}
else
{
	die('Did not match the correct pattern.');
}

?>

This code outputs:

string(64) “Jan-19-12 03:11:31 85.54.177.0 – invalid HELO: ‘PC100521998230’”

thank you but my question was more general

suppose I have

$output=“alex domain [test] sdfsdf [pippo] sdfdsf”;

I should have as result this

$output=“alex domain sfsdf sdfdsf”;

which is the required regular expression ?

I am trying

\[[a-zA-Z]\]

/ \[\[A-Za-z]\]/

none seems to work …

Thank you

I am getting help from http://gskinner.com/RegExr/ now , however I can’t find a way

If you just want to remove stuff in square brackets, try the following:

$output = "alex domain [test] sdfsdf [pippo] sdfdsf";
$output = preg_replace("#\\[[a-zA-Z0-9]+\\]#", "", $output);
var_dump($output);

I need exactly this, thank you!