开发者

Regular expressions src="http"

开发者 https://www.devze.com 2023-03-13 02:21 出处:网络
I have the following string and I need a regular expression for mysql to find \"something\" <img alt=\"\" src=\"http://something/sites/default/files/product_content\" />

I have the following string and I need a regular expression for mysql to find "something"

<img alt="" src="http://something/sites/default/files/product_content" />

I have tried:

SELECT `regex_replace`('src="http:/开发者_开发知识库/([^/]+)/teo/sites/default/files/', 'whatIWant', '<p>        <img alt="" src="http://something/teo/sites/default/files/product_content/img"/></p>');

but it doesn't work.


I'm not in a place where I can test it but try something like this: @src=['"]http://([^/]+)/@

Use the @ symbol to surround your pattern instead of traditional slashes so you don't have to escape every slash. Look for " or ' after src= because single quotes are valid too. Search for http:// followed by (NOT a slash character, one or more) After that look for a slash character.

So, the short story is it's easier to search for NOT a slash than try to search for every character that could appear in the domain name.


Most likely your something may have dots in it since it looks like a domain, so this is the PHP regex you want to use
'%http://([\w\.]*)/sites/default/files%im'

0

精彩评论

暂无评论...
验证码 换一张
取 消