使用正则表达式删除空行 [英] Remove Empty lines using Regular Expression

查看:286
本文介绍了使用正则表达式删除空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 开发新手,我有如下数据,我想删除所有空行,请告诉我要应用的模式:

I'm new to iOS develoment, I have the data like this below and i want to remove all the empty lines, Please let me know what the pattern to be applied:

我已将模式用作@"(\r\n)" 并将其替换为@"",但它不起作用.请帮我解决这个问题

I have used the pattern as @"(\r\n)" and replaced it with @"", but it does not work. Please help me to sort out this issue

#EXTINF:-1 tvg-name="seedocs" tvg-logo="RT",RT





http://rt.ashttp14.visionip.tv/live/rt-global-live-HD/playlist.m3u8

#EXTINF:-1 tvg-name="hsn" tvg-logo="hsn",HSN TV

rtsp://hsn.mpl.miisolutions.net:1935/hsn-live01/_definst_/mp4:420p500kB31

#EXTINF:-1 tvg-name="us" tvg-logo="us",USTwit

http://bglive-a.bitgravity.com/twit/live/high

#EXTINF:-1 tvg-name="ALJAZEERA" tvg-logo="aljazeera",Aljazeera

rtmp://aljazeeraflashlivefs.fplive.net/aljazeeraflashlive-live/aljazeera_eng_high

#EXTINF:-1 tvg-name="bbc" tvg-logo="bbc",BBC World News



#EXTINF:-1 tvg-name="vevo" tvg-logo="vevo",Vevo

http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch1/06/prog_index.m3u8

#EXTINF:-1 tvg-name="vevo2" tvg-logo="vevo2",Vevo 2

http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch3/06/prog_index.m3u8

#EXTINF:-1 tvg-name="1HD" tvg-logo="1HD",1HD

rtmp://109.239.142.62/live/livestream3

推荐答案

搜索:(?:\r?\n){2,}替换:\r\n

\r?\n 同时兼容 Windows 和 Linux.{2,} 表示两个或多个实例"

\r?\n is both Windows and Linux compatible. {2,} means "two or more instances"

演示

如果支持,您可以使用 \R 而不是 \r?\n 来包含其他类型的 Unicode 换行符.这在未来可能会有用,如果现在没有的话.

If supported, you can use \R instead of \r?\n to include other types of Unicode newlines. This may be useful in the future, if not at present.

这篇关于使用正则表达式删除空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆