使用正则表达式从 NSString 中获取 URL
我有一个使用 Google 的 GDataXML 解析器从 XML 解析出来的字符串,现在我需要进一步缩小该字符串的范围。该字符串的内容当前如下所示:
<Side><Image source='http://website.stuff.edu/img/user'/></Side>
我无法更改 xml 的传入方式,因此这是我必须解析的字符串。我已经尝试过这个正则表达式:
http:(.*?)'
但它抓取了我不想要的网址的结尾引号,我只需要从http抓取到网址的末尾...
我知道这很简单,但我不是确定语法。感谢您的帮助
I have a string that I have parsed from XML using Google's GDataXML parser, and now I need to get the string narrowed down a little bit more. THe contents of the string currently looks like this:
<Side><Image source='http://website.stuff.edu/img/user'/></Side>
I can't change the way the xml is coming, so this is the string I have to parse. I have tried this regex:
http:(.*?)'
But it grabs the ending quote of the url which I don't want, I just need to grab from http to the end of the url...
I know this is like stupidly easy, but I am not sure of the syntax. Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是怎么回事:
编辑 #1:
基本上,
[^']+
是“除了单引号 1 次或多次以外的任何内容”What about this:
EDIT #1:
Basically,
[^']+
is "anything other than single quote 1 or more times"