简体   繁体   English

使用Regex在ActionScript中搜索文本

[英]Search text in ActionScript with Regex

I am stuck in a problem. 我陷入了一个问题。 Actually developing search functionality. 实际开发搜索功能。 I am searching pattern for example in a following string: 我正在以下字符串中搜索模式:

test-123,this is demo.
testing?123,this is demo.
testing!jack,thanks.

Above are the three lines. 以上是三行。

What I want is as soon as I enter test it will search all the text (ie all three lines) and come with result: 我想要的是,一旦进入test ,它将搜索所有文本(即所有三行)并附带结果:

test-123
testing?123
testing!jack

It will search from beginning of every line till the comma character and would display the matched string. 它将从每一行的开头搜索到逗号,并显示匹配的字符串。 It should not truncate the special character before comma part. 它不应截断逗号前的特殊字符。

Like for example 例如

test
testing
testing

The Regular Expression which I am using and displaying the above pattern is 我正在使用并显示上述模式的正则表达式是

wordExp = ^wordHere\\w*
var iRegExp:RegExp = new RegExp(wordExp, "/gm");  

It should include all the character before comma. 它应包括逗号前的所有字符。

Please suggest the regular expression for above problem. 请提出上述问题的正则表达式。

I think you should change \\w to [^,]* 我认为您应该将\\ w更改为[^,] *

Something like this, if your line will always start with given word: 如果您的行始终以给定的单词开头,则类似这样:

^wordHere[^,]*

OR can be everywhere before comma : 或者可以在逗号前无处不在:

^[^,]*wordHere[^,]*

I hope I helped 我希望我能帮助

我不知道动作脚本,但这可以完成任务:

^([^,]+)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM