javascript - 用于使用环视删除空行的正则表达式
问题描述
解决方案
您不需要断言,因为它们是一次性使用的。
您不能在全局上下文中使用它们,因为您
在其中使用了两个锚点^$
。
因此,它们是无用的。
要区分换行符,只需添加捕获组。
另外,不要在字符类中使用 Unicode 字符,你可能
有一天会犯错。
就像我会做的那样......
/^[\u300c\u300e][^\r\n]+[\u300f\u300d](\s*\r?\n\s*\r?\n\s*)[\u300c\u300e][^\r\n]+[\u300f\u300d]$/
展开
^
[\u300c\u300e]
[^\r\n]+
[\u300f\u300d]
( # (1 start)
\s*
\r? \n \s*
\r? \n \s*
) # (1 end)
[\u300c\u300e]
[^\r\n]+
[\u300f\u300d]
$
推荐阅读
- javascript - 在 Javascript 中动态初始化 Dropzone(在运行时)
- angular - 自定义 TypeScript 类型定义文件被忽略
- laravel - 升级后 Laravel 5.3 Roles And Permissions 包错误
- ios - 有没有办法在不停机的情况下轮换 APNs Auth token + Key ID?
- javascript - 有什么方法可以将 Node 项目转换为 Deno?
- wordpress - ACF - 过滤关系查询以显示此类别中可用的 WooCommerce 产品
- android - 如何修复 android webview 应用程序中的字符串错误?
- javascript - 如何指定要使用的 API 数据?
- azure - 使用 .NET sdk 获取所有 Azure 数据工厂管道运行
- flutter - Flutter CircularprogressIndicator 未正确显示