Regular expressions in PHP

So I’m trying to write a regular expression in PHP but am running into what I’m guessing are some simple complications.

The regex I’m writing should detect any string of the following form: (ID: [number])
I currently have it defined like so:
[php]$namestr_regex = ‘/(ID: [0-9]+)/’;
// Examples of strings the regex should detect:
// (ID: 3)
// (ID: 60383)
// (ID: 0)
// Examples of strings the regex should not detect:
// ID: 495
// (ID: )
// (ID 34)[/php]

However, using the folowing code snippet, none of the above examples are detected and filtered.
[php]$body = preg_replace($namestr_regex,‘Extraneous ID removed’,$body);[/php]

Could anyone with more experience in PHP regular expressions tell me what I’m doing wrong here?

Nevermind, it turns out that I was only calling preg_replace in one of the three situations where this regex should be filtered, and I was testing it with the other two.

Sponsor our Newsletter | Privacy Policy | Terms of Service