glMatrix不工作?(glMatrix not working?)
当我记录我的this.kernel时,值不会改变。 但我认为他们应该这样做。 遵循文档它应该工作, http://glmatrix.net/docs/2.2.0/symbols/vec3.html#.normalize
this.kernel = []; this.kernelSize = 16.0; var max = 1.0; var min = -1.0; var a = Math.random(); for (var i = 0; i < this.kernelSize; i++){ this.kernel.push(Math.random() * (max - min) + min); // random float, range -1..1 this.kernel.push(Math.random() * (max - min) + min); this.kernel.push(Math.random()); //random float, range 0..1 vec3.normalize([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], [this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 +2]]); console.log(this.kernel); vec3.multiply([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], a, 1.0); console.log(this.kernel); }
When I log my this.kernel, the values don't change. But I think they should. Following the documentation it should work, http://glmatrix.net/docs/2.2.0/symbols/vec3.html#.normalize
this.kernel = []; this.kernelSize = 16.0; var max = 1.0; var min = -1.0; var a = Math.random(); for (var i = 0; i < this.kernelSize; i++){ this.kernel.push(Math.random() * (max - min) + min); // random float, range -1..1 this.kernel.push(Math.random() * (max - min) + min); this.kernel.push(Math.random()); //random float, range 0..1 vec3.normalize([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], [this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 +2]]); console.log(this.kernel); vec3.multiply([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], a, 1.0); console.log(this.kernel); }
原文:https://stackoverflow.com/questions/17382604
最满意答案
首先,分析您当前的正则表达式以及它为什么不起作用:
@
是文字@
字符,这里没什么可看的[...]
是一个角色类。 它将匹配它包含的任何(一个)字符[az\d_]
是一个由每个小写字母,每个数字(由它们自己的字符类\d
)和下划线组成的字符类+
是一个量词,这意味着它修改的令牌必须至少匹配一次并且可以匹配多次。 这里它适用于前一个字符类/pattern/flags
是Javascript的正则表达式语法之一i
是不区分大小写的标志。 在这种情况下,它意味着字符类也将匹配大写字母,尽管它只包含小写字母g
是全球旗帜。 这意味着正则表达式将尝试匹配多个结果,而不是在第一次遇到时返回。所以你试图匹配
@User Name Can Have Spaces(userId: number)
,但你的正则表达式与你提到的空格不匹配,也不是括号。您可以将这三个字符添加到字符类中,如下所示:
/@([a-z\d_ ()]+)/gi
但是,至少在我看来,对你想要匹配的东西的更好的描述将是:
/@[a-z\d_ ]+\(\d+\)/gi
我们匹配的用户名可以包含字母,数字,下划线和空格,后跟左括号,数字和右括号。 括号必须被转义,因此它们被理解为文字字符而不是正则表达式组。
如果要分别轻松提取用户名和用户ID,您可能希望使用以下内容,它们分别在各自的组中分组:
/@([a-z\d_ ]+)\((\d+)\)/gi
这是一个测试它的regex101链接 。
First, an analysis of your current regex and why it doesn't work :
@
is the literal@
character, nothing to see here[...]
is a character class. It will match any (one) of the characters it contains[a-z\d_]
is a character class composed of every lowercase letter, every digit (represented by their own character class\d
) and the underscore+
is a quantifier which means the token it modifies must be matched at least once and can be matched more than once. Here it applies to the previous character class/pattern/flags
is one of Javascript's regular expressions syntaxi
is the case-insensitive flag. In this case, it means the character class will also match uppercase letters although it only contains lowercase lettersg
is the global flag. It means that the regex will attempt to match multiple results rather than returning on the first encountered.So you're trying to match
@User Name Can Have Spaces(userId: number)
, but your regex does not match spaces as you mentionned, nor parenthesis.You could add these three characters to the character class, as follows :
/@([a-z\d_ ()]+)/gi
However, a better traduction of what you're trying to match, in my opinion at least, would be the following :
/@[a-z\d_ ]+\(\d+\)/gi
Where we match an username that can contain letters, digits, underscores and spaces, followed by an opening parenthesis, a number and a closing parenthesis. The parenthesis must be escaped so they are understood as the literal character rather than an regex group.
If you want to extract easily the username and the user id separately, you might want to use the following, where they are each grouped in their respective group :
/@([a-z\d_ ]+)\((\d+)\)/gi
Here's a regex101 link to test it.
相关问答
更多-
请注意,第二个匹配(来自 )是)/否定前瞻(?!\/>)仅禁止\/>在匹配 ),因此满足负条件。 如果您确定要匹配的模式总是有空格,那么您可以简单地将空间设置为空间,并且您将只获得您想要的空间: ...
-
首先,分析您当前的正则表达式以及它为什么不起作用: @是文字@字符,这里没什么可看的 [...]是一个角色类。 它将匹配它包含的任何(一个)字符 [az\d_]是一个由每个小写字母,每个数字(由它们自己的字符类\d )和下划线组成的字符类 +是一个量词,这意味着它修改的令牌必须至少匹配一次并且可以匹配多次。 这里它适用于前一个字符类 /pattern/flags是Javascript的正则表达式语法之一 i是不区分大小写的标志。 在这种情况下,它意味着字符类也将匹配大写字母,尽管它只包含小写字母 g是全球旗 ...
-
当我试图替换@mention时,为什么正则表达式不起作用?(Why is regex not working when I'm trying to replace a @mention?)[2023-06-27]
那是因为你已经将regex创建为一个字符串。 当你传递一个字符串replace方法时,它不会像正则表达式那样对待它; 它查找要替换的字符串的字面值。 改为使用正则表达式文字: var regex = /@([a-z0-9_]+)/; replacedText = replacedText.replace(regex, '$1'); 或者调用RegExp构造函数: var regex = new RegExp('@([a-z0-9_]+)') ... -
你可以使用这个正则表达式(\@(?P
[a-zA-Z\-\_]+)) : [a-zA-Z\-\_]+))" ,$text, $matches); var_dump($matches['names']); 在这个例子中,我使用了 ... -
jquery.mention默认文本(jquery.mention Default Text)[2022-12-15]
我查看了jquery.mentionsinput并调整了resetInput函数。 设置newMentionText时,我删除了Match [1]元素,即@符号。 function resetInput(currentVal) { mentionsCollection = []; var mentionText = utils.htmlEncode(currentVal); var regex = new RegExp("(" + settings.t ... -
正则表达式采取1231 - peterwateber和88 - hi是 preg_match_all("#@\[(\w+)\:(\w+)\]#', $str); 这取决于输入字符串中的字符类型。 \w假设您只有“单词”字符(字母和数字)。 $hidden_input = '@[123:web]hello world!'; preg_match('#@\[(\w+)\:(\w+)\]\s*(.*)$#', $hidden_input, $m); echo ''.$m ...
-
演示jsFiddle JS function() countChecked { return $("input:checked").length; }; $(function(){ $("div#signup label").checkmate(); $( "div#signup label" ).click(function(e) { var count = countChecked(); if ( count < 6 ) { ...
-
(?
推文中的正则表达式:匹配@reply而不匹配@mention(Regex in a Tweet: match @reply WITHOUT matching @mention)[2022-04-29]
^(@\w+\s)+将仅在字符串开始处匹配所有前缀“@reply”(s)。 regex101.com演示 ^(@\w+\s)+ will match all the prefixed "@reply"(s) at beginning of string only. regex101.com demo通常,您在这里遇到的问题是您在单词的开头和结尾处使用了捕获组,这意味着这些字符会从进一步的RegEx匹配中消耗掉。 这是因为你做: (?:...) 。 相反,你可以使用一个特殊类别的捕获组,它不消耗字符,称为Lookahead : (?=...) 在RegEx中,有Lookbehind AND Lookahead,它分别在RegEx之前和之后进行检查。 对你的问题的完美答案将使用lookbehind作为字符串的开头(?<=^|\s)和lookahead作为字符串的结尾(?=\s|$) 。 不幸的是,在Jav ...相关文章
更多- Working on Free Software
- 工作区和暂存区-git入门教程
- 最近工作回顾
- 不知道如何找工作
- 工作流系统
- phpHiveAdmin是如何通过Hive/Hadoop工作的
- 每天工作心得
- storm工作原理浅析
- Apache POI创建工作簿、打开现有工作簿
- 在苏州工作的朋友请进来赐教
最新问答
更多- python的访问器方法有哪些
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。
- 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
- 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
- NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
元素上的盒子阴影行为(box-shadow behaviour on elements) - Laravel检查是否存在记录(Laravel Checking If a Record Exists)
- 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
- 想学Linux 运维 深圳有哪个培训机构好一点
- 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
- 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
- AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
- 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
- 等待EC2实例重启(Wait for an EC2 instance to reboot)
- 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
- 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
- 江民杀毒软件的KSysnon.sys模块是什么东西?
- 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
- sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
- 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
- AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
- SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
- PerSession与PerCall(PerSession vs. PerCall)
- C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
- 平衡一个精灵(Balancing a sprite)
- n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
- Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
- 湖北京山哪里有修平板计算机的