regex - 来自字符串末尾的正则表达式延迟匹配
问题描述
是否可以从字符串末尾执行惰性匹配?
人为的例子:
let str = "It's the end of the world as we know it"
let regex = /n.+$/
str.match(regex) //finds "nd of the world as we know it"
很简单,它从字符串末尾找到 1 个或多个任意字符,直到找到最后一个“n”(向后)。
但是,现在假设我希望它从字符串末尾找到 1 个或多个任意字符,直到找到第一个“n”(向后)。您会认为您可以添加“惰性”量词,如下所示:
let regexLazy = /n.+?$/
但结果仍然是一样的:
str.match(regex) //finds "nd of the world as we know it"
从字符串末尾开始时是否可以进行惰性匹配?我错过了什么?谢谢!
解决方案
推荐阅读
- c# - Webform GridView 如何将具有相同用户但不同数据的行组合在一起?
- java - 为什么 avro 不能从 .avro 文件中获取模式?
- android - 在断电期间,SQLite 将我的数据库回滚到 BEGIN 之前的某个点
- forms - 字段之间的空间 - Netsuite 地址表单
- database - 从 PostgreSQL 中的两个表创建表时传播索引
- python - 初始化类时,我如何知道 **kwargs 参数中存储了哪些参数?
- reactjs - 无法读取 Reactjs 中未定义的属性“scrollIntoView”
- arrays - 如何解析下面格式的json数组
- reactjs - 如何为 OutlinedInput 覆盖悬停 notchedOutline
- javascript - 如何在 chrome 扩展内容脚本中使用 google api?