Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a general regexp to a PHP equivalent

Status
Not open for further replies.

ro88o

Programmer
Jun 25, 2005
24
GB
Hi,

I have a regular expression that I've created to find code comments in a piece of text which looks like this...

(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)

If I try to put this into preg_match_all in my PHP script however it returns the error:

Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '|'

Does anybody know how to modify my regexp to work in PHP?

Thanks in advance for any help you can offer!
Tom
 
Code:
$pattern = '/(\/\*([^*]|[\\r\\n]|(\*+([^*/]|[\\r\\n])))*\*+/)|(\/\/.*)/';

i may have got the above wrong, but basically you need to escape the special characters in the normal way for a php string, and you need to put pattern delimiters in. these go at the beginning and end (before the modifiers) of the pattern. I tend to use the forward slash as a delimiter, but I don't think that there are (m)any restrictions on what you choose.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top