Jump to content

match single line comments not existing within multiline comments


dsaba

Recommended Posts

haystack:

33w4bpd.png

 

I came up with this modeled after looking at a similar regex to match text not in html tags ( ~(?![^<]+>)\b(highlight|these|words|okay|text)\b~i  )

 

(?!(?:(?!/\*).)+\*/)//.*?\r\n

 

 

The problem is it doesn't match the 2 single line comments at the bottom of the haystack. Any ideas how to fix this?

 

Single line comments is // up until \r\n

 

Multiline comments are /* up until */

 

Thanks for looking.

 

*WOOPS -

I have a pattern that does match correctly, i will reply with it in a couple moments, so this question is solved.

how do I match the literal '/*' that is not in between // and $ (end of line marker)

 

~/\*~

will match in

//*/

 

i tried this:

~(?!(??!//)[^\r\n])*$)/\*~m

but it won't match in /* alone

 

it will only match in

/*//

or

/*   //

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.