Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.