ActionScript 3.0 :: Use The User Input Data As Part Of The Regular Expression?
Jul 6, 2011
This time want to know is it possible to use the user input string as part of reqular expression for instant search... I am aiming to add search feature in my game.. Where i m going to have several items available in list... what i am planning is to have a text box from which i will accept user input and perform instant search am still a noob in AS3... so whether using RegExp meet my goal ?
I've written a url validator for a project I am working on. For my requirements it works great, except when the last part for the url goes longer than 22 characters it breaks. My expression:/((https?)://)([^s.]+.)+([^s.]+)(:d+/S+)/i
It expects input that looks like "http(s)://hostname:port/location". When I give it the input: https://demo10:443/111112222233333444445
it works, but if I pass the input https://demo10:443/1111122222333334444455
it breaks. You can test it out easily at[URL].. Oddly, I can't reproduce the problem with just the relevant (I would think) part /(:d+/S+)/i. I can have as many characters after the required / and it works great. Any ideas or known bugs?
I'm creating a chat app and I would like to if someone enters a url that it turn color and turn into a hyperlink. I am not sure how to write the regular expression. I guess the approach would be to check for "http://" or "www." or ".com" ?
I'm trying to create a replace method that allows me to surround parts of a string with tags. I tried this with a regular replace technique (join and split) but thats case sensitive. what i want is:
: "A nice example line"
and replace "Ice" in that line to surround it with bold tags, result:
text: "A n<b>ice</b> example line"
ActionScript Code: var str:String = "A nice example line"; var pattern:RegExp = /(w+)-(w+)/gi; trace(str.replace(pattern, "$2,$1"));
I am trying to understand some basics of Regular Expressions.For just a experiment I wanted to count the total words in a string.var str:String = "hello, this is some text to count the word hello and to check if Hello is ignored by case and if hellow is different";[code]Here i get the array of the values. and using it's length I can use the total number. This works, but the regular expression is not dynamic.[code]
I have a string "4 + x + 5" and i want to change the x to 1x When using a regular expression for x i end up in an endless loop because when the x is changed to 1x, the regular expression finds the x in 1x and applies it to that Is there anyway of making is skip the next character? Here is my code:
Example: "My site is [URL] and yours is [URL]. Is Fred's [URL]? Or is it[URL]? (I thought his site was [URL], but clearly it's not."
This should extract
[URL]
Notes: it should assume that any punctuation following the url is NOT part of the url, e.g. the comma after [URL], is not part of the url. This includes trailing question marks, which I realize in actuality COULD be part of the url. Of course, if a question mark is followed by querystring data, it SHOULD be considered part of the url. Note that urls might be followed by multiple punctuation marks, as in the the case of (Is your url[URL])?
Urls (and their trailing punctuation, if any) will always be followed by a space, a newline/return character -- or they'll be the end of the string being tested.The will be preceded by a whitespace character or, possibly, an open bracket or parenthesis, as in "Please visit my site [URL]." Or they'll come at the beginning of the string.This regexp should work for http, https and ftp.This is for an Actionscript project. I believe that Actionscript uses the same regular-expression engine as Javascript.
so im trying to figure out regular expressions in Flex, but cant for the life of me figure out how to do the following.From the sample below, i need to extract out only "Mike_Mercury".So i have to somehow strip out everything around it with RegExp, or whatever's best. Also, I would need it to work with other samples as well. Im getting this from the reddit api, so id have to extract that same section from a whole bunch of these.
I am creating a simple application and wanted to use a function to match any given regular expression to any given string, so I created the following function:
PHP Code:
function validateStr(regexp:RegExp, strVal:String):Boolean{ if(regexp.exec(strVal)==null) return false; else return true; }
But I was wondering, can't I simply replace it with
PHP Code:
function validateStr(regexp:RegExp, strVal:String):Boolean{ return regexp.test(strVal); }
I am relatively new to ActionScript, so I do not know if both would present the same behavior.
Basically what I want to happen is to ignore scenario #2. I know the solution, but I can't seem to nail it. All that needs to happen is to select the http (and everything after that) as long as it's not preceded by a "> or =", but since I don't know a way for RegExp to look backwards, I'm sort of at a loss. Here's hoping that someone has run into this issue before
I'm trying to find the number of newlines in a string using the Actionscript 3.0 RegExp engine. Using the string.match function and RegExp(" ","g") does not find the newlines in a string which contains newlines. Is there something I need to add to the pattern or something else that I am missing?
I am using RegExp to search for character sequences within strings. I was wondering if/what is the proper way to use a string stored in a variable as a regular expression. For example: [code]I'll have to use another string manipulation tool to search for the sequence.
I want the user to input a regular expression, which is then used.
I'm using following at the moment.
PHP Code:
var filterEx = new RegExp(filterTxt.text.split("/")[1], filterTxt.text.split("/")[2]); filterTxt is a textbox, when traceing the pattern is seemingly correct, but i.e.:
give me the Regular Expression that can check if a given string has any HTML code in it, and coming to think of it I would be bothered with <a href="something">something</a> exactly.
Is it possible to create wrong Regular expression in ActionScript/Flex which will cause runtime error? I've tried so many weird regexpes in Flex and Flex never complained! How do I know If my regexp valid?
I've been struggling with this problem for a while:I have a string containing HTML and I'm using a regular expression to get the characters between the tags. I'm then attempting to apply a TextFormat to those characters.The problem is that I'm using the TextField's "htmlText" property instead of it's "text" property (because I don't want the HTML tags to be visible). So, the character index that's returned from the regular expression is incorrect, when I apply the TextFormat.Here is some sample code which illustrates the problem:
var txt:String = "<b>Sample</b> string with bold text"; var tf:TextField = new TextField(); addChild(tf);
find the suitable regular expression to validate a string that has comma separated numbers, for e.g. '1,2,3' or '111,234234,-09', etc. Anything else should be considered invalid. for e.g. '121as23' or '123-123' is invalid. I suppose this must be possible in Flex using regular expression but I can not find the correct regular expression.
I need a AS3 regular expression that allows me to find/replace in strings like these:
[Code]...
I want to be able to replace the spaces at the beginning (inside the > <) for other character. It shouldn't affect the number of character at the right of the spaces or the attributes in the value1 definition.
I'm sorry this is a question from a server ignoramus, I've previously captured user input using a combination of cfml and text files. That was way back in 2002 and using AS 1.0. I'm now working in an environment where the server guy won't put any scripts on, and I mean none, no PHP, no ASP, no CFML, nothing. Would anyone know if there is a way of capturing user input without using a script, please? This prolly shows a really basic lack of understanding of how servers work but I'm a bit desperate. I know the Flash Learning Interactions can work with SCORM and pop results into LMSs that use SCORM and our LMS does use SCORM, but it seems to only be within the learning interactions and I don't know where to start to tailor this for the input I need to capture.
I'm sure it's easy to do, but I just cannot figure it out. I've created a timer but want to let the user set default values to start at so they don't have to modify the start time each time the program starts.I was able to create a text box but it is un-editable in the actual program. It displays '00' nicely but it's useless. I haven't even gotten to the point where the data is pulled and stored.
ActionScript Code: var timerHrs1:TextField = new TextField(); timerHrs1.type = TextFieldType.INPUT;