开发者

Ruby regex replace all but what's within parenthesis

How do I replace all but what's within parenthesis

For instance:

some_html=some_html.gsub(/<a href=\"([^\"]+)\"/,  "");

now I would like to replace that string with: whatever 开发者_开发知识库is in the parenthesis.


I don't really understand your question, so if it needed feel free to correct me.

I assume you need to transform following <a href="needless[target]trash" into something like <a href="target"

So following code do the job:

some_html.gsub!(/(<a href=")[^"]*\[([^"]+)\][^"]*"/, '\\1\\2"')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜