huddy Posted May 16, 2012 Share Posted May 16, 2012 Hi All, I'm hoping you're able to help me with something, I need some regex to match EP01, E01 but to not match anything if it's anything it has s01, for example s01e01 which it currently does. Here's what I've got: /ep?(\d\d)/i Thanks for any help. Billy Quote Link to comment https://forums.phpfreaks.com/topic/262638-regex-pattern-to-not-match-if-string-contains-something/ Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 Maybe this'll work? /(s\d\d){0}e(p){0,1}\d\d/i Quote Link to comment https://forums.phpfreaks.com/topic/262638-regex-pattern-to-not-match-if-string-contains-something/#findComment-1346124 Share on other sites More sharing options...
requinix Posted May 16, 2012 Share Posted May 16, 2012 /(? [b](? Quote Link to comment https://forums.phpfreaks.com/topic/262638-regex-pattern-to-not-match-if-string-contains-something/#findComment-1346140 Share on other sites More sharing options...
smoseley Posted May 16, 2012 Share Posted May 16, 2012 /(?<!s\d\d)ep?\d\d/ (?<!X)Y means "Y if not preceded by X". Nice! I learned 2 things about regex in this thread! Quote Link to comment https://forums.phpfreaks.com/topic/262638-regex-pattern-to-not-match-if-string-contains-something/#findComment-1346157 Share on other sites More sharing options...
.josh Posted May 17, 2012 Share Posted May 17, 2012 Well if we're going with the assumption that s01 immediately precedes ep01 or e01, and that 01 is literal (as opposed to being any 2 digits, requinix's pattern would be more efficient just using literal 01 rather than char classes: /(?<!s01)ep?01/i Quote Link to comment https://forums.phpfreaks.com/topic/262638-regex-pattern-to-not-match-if-string-contains-something/#findComment-1346222 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.