Jump to content

preg_match || General problem with REGEX


jimmydorry

Recommended Posts

try '%\](.*?)(\(|\[)%mis'

Wow, it bloody works. Would you mind explaining what the '?' does, and how you knew to use it?

 

Thanks a heap man.

 

EDIT: From what I understand, it means that the phrase can occur 0 or 1 times.

 

? makes the .* "ungreedy", so it doesn't match the ( or [.  Alternate way (untested):

 

'%\][^\(\[]+[\(\[]%i'

 

Not sure if you needed the capturing parentheses but I removed them.

try '%\](.*?)(\(|\[)%mis'

Wow, it bloody works. Would you mind explaining what the '?' does, and how you knew to use it?

 

Thanks a heap man.

 

EDIT: From what I understand, it means that the phrase can occur 0 or 1 times.

 

? makes the .* "ungreedy", so it doesn't match the ( or [.  Alternate way (untested):

 

'%\][^\(\[]+[\(\[]%i'

 

Not sure if you needed the capturing parentheses but I removed them.

I understand your alternate solution better, and will have to try it later. Thanks for the explanations though, and for both solutions.

 

If I understand correctly, the alternate solution utilises the regex operator of NOT EQUAL TO. Thus it is saying grab everything after ']' that is not '(' OR '['.

I understand your alternate solution better, and will have to try it later. Thanks for the explanations though, and for both solutions.

 

If I understand correctly, the alternate solution utilises the regex operator of NOT EQUAL TO. Thus it is saying grab everything after ']' that is not '(' OR '['.

 

Yes.  I'm not sure if it makes a difference but I tend to use character classes [] a lot.

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.