另一种积极看待背后的方法
除了积极的回顾之外还有其他选择吗?我问这个问题是因为我创建了以下正则表达式,我将在特定软件中使用它:
(?<=function )[a-zA-Z]([A-Za-z]|[0-9])*
但是,显然该软件不接受这种形式作为有效的正则表达式。所以我需要一个正则表达式,它唯一地采用单词后跟“function”。谁能告诉我如何做到这一点或者这是否真的可以做到?据我所知,做到这一点的唯一方法是后视。
is there any alternative to the positive lookbehind? I ask because I created the following regex that I will use in a specific software:
(?<=function )[a-zA-Z]([A-Za-z]|[0-9])*
However, apparently this software does not accept this form as a valid regex. So I would need a regex that uniquely takes the word followed by "function". Could anyone let me know how this could be done or if this could actually be done? The only way to do this that I know of is the lookbehind.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正在尝试查找字符串“function”,后跟包含字母和数字的函数名称?无需环顾四周。
请注意,您原来的
[A-Za-z]|[0-9]
最好写成[A-Za-z0-9]
。编辑:如果您只想要“功能”之后的单词,那么您可以使用捕获组:
如何使用捕获组取决于您正在使用的工具或语言,而您没有指定这些工具或语言。
Are you trying to find the string "function" followed by a function name with letters and digits? No lookarounds are necessary.
Note that your original
[A-Za-z]|[0-9]
is better written as[A-Za-z0-9]
.EDIT: If you want just the word after "function" then you use a capture group:
How you use the capture group depends on the tool or language you're using, which you didn't specify.