【问题标题】:Is it possible to not limit the upper value of a regex range for a repetition of a character (Infinite)? [duplicate]是否可以不限制重复字符(无限)的正则表达式范围的上限? [复制]
【发布时间】:2019-01-23 04:59:19
【问题描述】:

是否可以不限制字符重复的正则表达式范围的上限?我不确定这是否可能。在此示例中,我使用 infinity 作为占位符:

let lowerLimit = 2; // Or any value
let regex = RegExp ("[\n]{" + lowerLimit + ",Infinity}", "g");

【问题讨论】:

  • [\n]+ for 1 or more

标签: javascript regex infinite


【解决方案1】:

只取一个没有值的逗号作为最大量词。

{n,} 

使用您的代码

let lowerLimit = 2; // Or any value
let regex = RegExp ("[\n]{" + lowerLimit + ",}", "g");
//                                          ^^

【讨论】:

  • 谢谢!它完全按照我的意愿工作! SO让我接受后会接受!
猜你喜欢
  • 1970-01-01
  • 2018-09-07
  • 1970-01-01
  • 2017-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多