jimmydorry Posted March 2, 2011 Share Posted March 2, 2011 I can't seem to get this OR statement working... it's the '|' character. expression: '%\](.*)(\(|\[)%mis' string: '[HnG] DD Hokuto no Ken 02 (TV) [8BC696B8].avi' result: ' DD Hokuto no Ken 02 (TV) ' expected result: ' DD Hokuto no Ken 02 ' Quote Link to comment Share on other sites More sharing options...
sasa Posted March 2, 2011 Share Posted March 2, 2011 try '%\](.*?)(\(|\[)%mis' Quote Link to comment Share on other sites More sharing options...
jimmydorry Posted March 2, 2011 Author Share Posted March 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 2, 2011 Share Posted March 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 2, 2011 Share Posted March 2, 2011 Not sure if you needed the capturing parentheses but I removed them. Oh, I see you did: '%\]([^\(\[]+)[\(\[]%i' Quote Link to comment Share on other sites More sharing options...
jimmydorry Posted March 2, 2011 Author Share Posted March 2, 2011 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 '['. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 2, 2011 Share Posted March 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
jimmydorry Posted March 2, 2011 Author Share Posted March 2, 2011 Oh, and your solution worked as intended. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.