![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've been trying to find this, but I'm not sure that I'm using the right terminology. Sorry if this is an FAQ. I'm trying to SELECT something using a non-greedy wildcard. I know to use % for a greedy wildcard, but how would I correctly do the following in MySQL? %<img(.*?)src="*(\s*)<a% Reading it out, I'm searching for anything, followed by <img, followed by any character (or no character) preceding src=, followed by " or no ", followed by a whitespace or no whitespace, followed by <a, followed by anything else. TIA, Jason |
#3
| |||
| |||
|
|
*You mean - use a regexp?? http://dev.mysql.com/doc/refman/5.1/en/regexp.html select * from table where col1 REGEXP '%<img(.*?)src="*(\s*)<a%'; |
#4
| |||
| |||
|
|
*You mean - use a regexp?? http://dev.mysql.com/doc/refman/5.1/en/regexp.html select * from table where col1 REGEXP '%<img(.*?)src="*(\s*)<a%'; HA! I should have known it would be something as simple as that. I'm getting an error using that, but I'm sure I'll figure it out. The error is: 'repetition-operator operand invalid' from regexp |
#5
| |||
| |||
|
|
On Mar 24, 8:47*pm, jwcarlton <jwcarl... (AT) gmail (DOT) com> wrote: *You mean - use a regexp?? http://dev.mysql.com/doc/refman/5.1/en/regexp.html select * from table where col1 REGEXP '%<img(.*?)src="*(\s*)<a%'; HA! I should have known it would be something as simple as that. I'm getting an error using that, but I'm sure I'll figure it out. The error is: 'repetition-operator operand invalid' from regexp Narrowing it down, I'm still getting the same error on this: SELECT * FROM table WHERE col1 REGEXP 'img(.*?)' The "repetition-operator" would have to be the *, right? According to the dev.mysql.com link above, this is valid? |
#6
| |||
| |||
|
|
On Mar 24, 9:09 pm, jwcarlton<jwcarl... (AT) gmail (DOT) com> wrote: On Mar 24, 8:47 pm, jwcarlton<jwcarl... (AT) gmail (DOT) com> wrote: You mean - use a regexp?? http://dev.mysql.com/doc/refman/5.1/en/regexp.html select * from table where col1 REGEXP '%<img(.*?)src="*(\s*)<a%'; HA! I should have known it would be something as simple as that. I'm getting an error using that, but I'm sure I'll figure it out. The error is: 'repetition-operator operand invalid' from regexp Narrowing it down, I'm still getting the same error on this: SELECT * FROM table WHERE col1 REGEXP 'img(.*?)' The "repetition-operator" would have to be the *, right? According to the dev.mysql.com link above, this is valid? For anyone else reading this, the ? apparently doesn't translate to "not greedy" in MySQL; I removed it, and the regex worked fine. So, while REGEXP did work for this particular application, I'm assuming that it's still greedy, so it doesn't exactly work in all applications. |
#7
| ||||||
| ||||||
|
|
I've been trying to find this, but I'm not sure that I'm using the right terminology. Sorry if this is an FAQ. I'm trying to SELECT something using a non-greedy wildcard. I know to use % for a greedy wildcard, but how would I correctly do the following in MySQL? %<img(.*?)src="*(\s*)<a% |
|
'abcdefdefg' like 'ab%defg%' | +------------------------------+ 1 | +------------------------------+ |
|
'abcdefdefg' like 'ab%def%' | +-----------------------------+ 1 | +-----------------------------+ |
|
'foo<img src=bar.jpg><a blubb' LIKE '%<img%' | +----------------------------------------------+ 1 | +----------------------------------------------+ |
|
'foo<img src=bar.jpg><a blubb' LIKE '%<img%src=%' | +---------------------------------------------------+ 1 | +---------------------------------------------------+ |
|
'foo<img src=bar.jpg><a blubb' LIKE '%<img%src=%<a%' | +------------------------------------------------------+ 1 | +------------------------------------------------------+ |
![]() |
| Thread Tools | |
| Display Modes | |
| |