yaba Posted September 13, 2006 Share Posted September 13, 2006 Hello,I need a REGEXP that would match a phrase that contains a word starting with some characters, but would not match a phrase that starts with a word, starting with those chars! ???Here's an example:search chars = 'abc''sss abcsss' (match)'sss abc abcsss' (match)'abc sss abcsss' (no match)I thought this (when calling from PHP) would work:[code=php:0]"SELECT * FROM words where wrd REGEXP '^[^({$chars})].*[[:<:]]{$chars}' ORDER BY wrd ASC";[/code]but it doesn't. It will match 'sss abc', but it won't match things like 'sss[b]abc[/b]sfg abc'.Any help greatly appreciated :D Link to comment https://forums.phpfreaks.com/topic/20589-regexp-not-at-the-beginning-of-string/ Share on other sites More sharing options...
shoz Posted September 13, 2006 Share Posted September 13, 2006 [quote=yaba]I need a REGEXP that would match a phrase that contains a word starting with some characters, but would not match a phrase that starts with a word, starting with those chars![/quote]If by [not]starting with some characters you mean a string, with characters in a specific order then the following should be what you're looking for[code]SELECT*FROMwordsWHEREwrdNOT LIKE '{$chars}%'AND wrd REGEXP('[[:<:]]{$chars}');[/code][quote=yaba]thought this (when calling from PHP) would work:"SELECT * FROM words where wrd REGEXP '^[^({$chars})].*[[:<:]]{$chars}' ORDER BY wrd ASC";but it doesn't. It will match 'sss abc', but it won't match things like 'sss[b]abc[/b]sfg abc'.[/quote]You stated that the characters should begin a word, not be in any part of the word. So I don't understand this comment.The regexp that you posted will work if you're saying that the word shouldn't start with any of the characters in the string.eg:if $chars = 'abc'then the regexp won't match strings like the following'a abc foo''b abcd bar''c oeirr'The only error would be the inclusion of the brackets (). It should be[code]^[^{$chars}][/code]I assume that you "misspoke" when you said that the phrase should not start with any of the characters and instead meant that the phrase should not start with the string. In which case the query I posted should work. Link to comment https://forums.phpfreaks.com/topic/20589-regexp-not-at-the-beginning-of-string/#findComment-90948 Share on other sites More sharing options...
yaba Posted September 13, 2006 Author Share Posted September 13, 2006 Yup, that did it! Thanks ;)I indeed got confused trying to express myself! ??? Link to comment https://forums.phpfreaks.com/topic/20589-regexp-not-at-the-beginning-of-string/#findComment-91133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.