gpt4 book ai didi

javascript - 在 solidity 文件中查找结构

转载 作者:行者123 更新时间:2023-11-29 20:55:08 27 4
gpt4 key购买 nike

我在文本文件中有下一个结构:mapping(address => uint) public lockedAddresses; 我想找到它。我尝试使用下一个正则表达式:mapping\s*\([\w\s=>\d]\)\s+(public\s+)?lockedAddresses。我不明白如何找到它。

var string = 'event Release();\n address public holder;\n	mapping(address => uint) public lockedAddresses;\n 	modifier isReleased () {\n	require(released || msg.sender == holder || msg.sender == owner);\n		require(lockedAddresses[msg.sender] <= now);\n		_;\n	}';

var position = string.search(/mapping\s*\([()\w\s=>\d]\)\s+(public\s+)?lockedAddresses/);

console.log(position);

如何在文本中找到结构:mapping(address => uint) public lockedAddresses;??

最佳答案

打开后需要重复字符类[()\w\s=>\d]+一次或多次才能匹配address => uint括号 (.

mapping\s*\([()\w\s=>\d]+\)\s+(public\s+)?lockedAddresses                        ^

var string = 'event Release();\n address public holder;\n	mapping(address => uint) public lockedAddresses;\n 	modifier isReleased () {\n	require(released || msg.sender == holder || msg.sender == owner);\n		require(lockedAddresses[msg.sender] <= now);\n		_;\n	}';
var position = string.search(/mapping\s*\([()\w\s=>\d]+\)\s+(public\s+)?lockedAddresses/);
console.log(position);

要完全匹配 mapping(address => uint) public lockedAddresses; 您应该在正则表达式后附加一个分号(您可以使 (public\s+) 成为非捕获组):

mapping\s*\([()\w\s=>\d]+\)\s+(?:public\s+)?lockedAddresses;

关于javascript - 在 solidity 文件中查找结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49694785/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com