00:00
00:00
Newgrounds Background Image Theme

apollonx just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

The Flash 'Reg' Lounge

3,046,926 Views | 60,186 Replies
New Topic Respond to this Topic

Response to The Flash 'Reg' Lounge 2014-01-09 00:28:11


At 1/9/14 12:14 AM, egg82 wrote:
At 1/9/14 12:10 AM, TheNavigat wrote: I hate you. My internet connection is around 0.4~0.5 Mbps. Seriously. Sending a USB Flash drive with a pigeon holding the data is faster than download it with that speed.
25/5 which is pretty middle-of-the-road.
I wish our upload was faster though, it sucks not being able to stream at 1080p60 and it takes several hours to upload a YouTube video :(

It sucks not being able to WATCH a fucking 360p video without leaving it to buffer every now and then.


Nav.. I'm the Nav!

Response to The Flash 'Reg' Lounge 2014-01-09 00:33:31


/[\s\t\n]*>(\w+)[\s\t]*=[\s\t]*(?:(?:"(.*?)")|>(\w+))[\n\t\s]*/gsm

Response to The Flash 'Reg' Lounge 2014-01-09 04:09:22


At 1/9/14 12:33 AM, slugrail wrote: /[\s\t\n]*>(\w+)[\s\t]*=[\s\t]*(?:(?:"(.*?)")|>(\w+))[\n\t\s]*/gsm

Okay I give up. What is this round-square bracket, \letter, multiplication, equality and comparison signs mess?

Response to The Flash 'Reg' Lounge 2014-01-09 07:18:09


At 1/9/14 04:09 AM, kkots wrote:
At 1/9/14 12:33 AM, slugrail wrote: /[\s\t\n]*>(\w+)[\s\t]*=[\s\t]*(?:(?:"(.*?)")|>(\w+))[\n\t\s]*/gsm
Okay I give up. What is this round-square bracket, \letter, multiplication, equality and comparison signs mess?

Remove all white space? The less than and equals are throwing me off. Also fuck regex

Response to The Flash 'Reg' Lounge 2014-01-09 07:29:59


First thing first:

Too many redundant \t and \n's :P

So simplifying it we get:

/\s*>(\w+)\s*=\s*(?:(?:"(.*?)")|>(\w+))\s*/gsm

And it will basically match either this:

>Test = "Hello World"

or this..

>Test2 = >Test

Which means I'm parsing -

Response to The Flash 'Reg' Lounge 2014-01-09 08:32:04


At 1/9/14 04:09 AM, kkots wrote:
At 1/9/14 12:33 AM, slugrail wrote: /[\s\t\n]*>(\w+)[\s\t]*=[\s\t]*(?:(?:"(.*?)")|>(\w+))[\n\t\s]*/gsm
Okay I give up. What is this round-square bracket, \letter, multiplication, equality and comparison signs mess?

First time encountering regular expressions, eh? They're equal parts useful, tedious, and cumbersome.

At 1/9/14 07:29 AM, slugrail wrote: Too many redundant \t and \n's :P

You still have redundancies and some problems. You don't need to match whitespace at the beginning and end of the regex, the results are the exact same regardless of doing that. The way you're matching will also return a null result because you have two capture groups that can never both capture at the same time, and non-capture groups that just over-complicate the regex. You will need to pick one syntax or the other, or match them using two separate pieces of regex.

This is how I would match them:

For matching the one with quotations

>([^\s]+)\s*=\s*"([^"]+)"

For matching the one with just the brackets

>([^\s]+)\s*=\s*>(\w+)

However that's assuming you intended to only match alpha-numeric characters for the second part. If you want to match all characters like in the one with the quotations (excluding the fact that quotations can't be matched for those) you would need to do something like this:

>([^\s]+)\s*=\s*>(.)+

I also don't see any need for the flags that you're using, but I also don't know what type of data you intend to match with this, or what problem you're solving.

Response to The Flash 'Reg' Lounge 2014-01-09 08:34:53


I also don't know how proficient you are with regular expressions, so if you don't understand the changes I made I can explain them.

Response to The Flash 'Reg' Lounge 2014-01-09 09:01:19


In case anyone is doing regex without this for some reason:

http://gskinner.com/RegExr/

:D


- Matt, Rustyarcade.com

Response to The Flash 'Reg' Lounge 2014-01-09 09:09:27


At 1/9/14 08:32 AM, Diki wrote:
At 1/9/14 04:09 AM, kkots wrote:
At 1/9/14 12:33 AM, slugrail wrote: /[\s\t\n]*>(\w+)[\s\t]*=[\s\t]*(?:(?:"(.*?)")|>(\w+))[\n\t\s]*/gsm
Okay I give up. What is this round-square bracket, \letter, multiplication, equality and comparison signs mess?
First time encountering regular expressions, eh? They're equal parts useful, tedious, and cumbersome.

Aha. Let's say, if I was about to learn RegExp on ActionScript 3.0, would it be useful? What are RegExp used for? Will they help programming (and if yes, then programming of what and why)?

Response to The Flash 'Reg' Lounge 2014-01-09 09:18:25


At 1/9/14 08:32 AM, Diki wrote: You will need to pick one syntax or the other, or match them using two separate pieces of regex.

That's a good idea I don't know what crossed my mind to squeeze them both into one expression.

>([^\s]+)

Ah very intuitive didn't think about that

:"([^"]+)"
Didn't think about excluding inner quotation marks either which would've led to another headache, good catch! (No pun intended) :P

I also don't see any need for the flags that you're using, but I also don't know what type of data you intend to match with this, or what problem you're solving.

The flags are there since I'll be retrieving a bunch of key->value pairs in one huge text file. I had the non-capturing groups as I didn't want to include the quotation marks or the '>' when extracting the value pairs in the 2-in-1 expression. I think splitting them into two expressions will solve that issue without the ncgroups and hardcoded == undefined checks, so that was a great idea and it simplifies the underlying AS3 code structure too!

Response to The Flash 'Reg' Lounge 2014-01-09 09:28:19


At 1/9/14 09:01 AM, Rustygames wrote: In case anyone is doing regex without this for some reason:

http://gskinner.com/RegExr/

D

I remember when I used to attempt writing regular expressions without these kinds of tools. No clue how I didn't go insane. Regex Buddy is my go-to tool though, but it's not free.

At 1/9/14 09:09 AM, kkots wrote: Aha. Let's say, if I was about to learn RegExp on ActionScript 3.0, would it be useful?

That depends. If you aren't ever working with text that needs to be parsed or manipulated then you probably won't need regular expressions, though it still wouldn't hurt to learn them. They're not so terrible once you learn what all the symbols are doing. This is an excellent book that can get you up to speed with them, even though it isn't finished.

At 1/9/14 09:09 AM, kkots wrote: What are RegExp used for? Will they help programming (and if yes, then programming of what and why)?

Basically they're just used to match patterns in text. For example, say you were to receive some blob of text and you wanted to match every instance of a lowercase vowel, you would just need to use this:

[aeiou]

The letters being inside the square brackets means it will look for each instance of any of those letters, so if you matched that against this text:

I talk to monkeys A LOT WOO

You would end up with this:

["a", "o", "o", "e"]

Because it's matching the a in "talk", the two os in "to" and "monkeys", as well as the e in "monkeys". The other vowels are ignored because they are uppercase. Want to instead match every word that only consists of uppercase letters? You could do this:

[A-Z]+

Regular expressions supports ranges like that, so doing A-Z inside the square brackets means it will match any uppercase letter that ranges from A to Z, which obviously means any uppercase letter. Match it against this:

foo bar BAZ butts WHAT

And you will receive:

["BAZ", "WHAT"]

Doing stuff like that can be very useful if you need to pull out data from large blobs of text, or if you need to replace patterns of text with something.

If you want to play around with them I recommend using one of the tools that I and Rustygames linked, as well as using a JavaScript console in whichever browser you use. Having a JS console makes playing around with them a lot easier, since you can just plop in something like this and immediately get a result:

"TACOS blah blah 42 woop FOO BAR ding dong".match(/[a-z0-9]+/g);

Note: for the sake of making all that easier to understand I didn't flags or capture groups, which are covered in the book that I linked (at least I think it covers flags, been a while since I read it).

Response to The Flash 'Reg' Lounge 2014-01-09 09:35:20


I'm also an idiot and forgot to explain what the plus symbol means when it's used like that. It just means that it will match whatever is in the square brackets one or more times, so when you do [A-Z]+ it will match any uppercase letter up until it reaches something that is not an uppercase letter, such as whitespace.

At 1/9/14 09:18 AM, slugrail wrote: Didn't think about excluding inner quotation marks either which would've led to another headache, good catch! (No pun intended) :P

To be fair the way you did it with "(.*?)" does the same thing, I just find "([^"]+)" more clear and easier to read.

At 1/9/14 09:18 AM, slugrail wrote: The flags are there since I'll be retrieving a bunch of key->value pairs in one huge text file.

Ah, okay, that makes sense. You'll definitely need the global flag and multiline flag then. I also just realised that since you're using the /s flag that using (.)+ to match the data with the triangle bracket will probably mess up your results. Changing it to (.*?) should suffice.

Response to The Flash 'Reg' Lounge 2014-01-09 10:00:12


At 1/9/14 09:28 AM, Diki wrote: That depends. If you aren't ever working with text that needs to be parsed or manipulated

This is dangerously close to what I am working on right now. Kind of funny that I'm learning about RegExp only now.

Basically they're just used to match patterns in text. For example, say you were to receive some blob of text and you wanted to match every instance of a lowercase vowel, you would just need to use this:
[aeiou]

Okay, I stared at this until I realized that a,e,i,o,u are all vowels of English alphabet. After this I understood everything else on the fly.

[A-Z]+

The plus sign... its purpose is undefined for me. Yet. *puts the link to the book into bookmarks*

Doing stuff like that can be very useful if you need to pull out data from large blobs of text, or if you need to replace patterns of text with something.

"pull out data from large blobs of text" - 100% match with my current problem.
Working on a dialogue editor for a game, which reads ActionScript 2.0 files (.AS) which define arrays of strings (dialogue responses or options) and numbers (what facial expression frame numbers to show). These .AS files are included (include "File1.as") into the main program. The dialogue editor reads.
Well, for now the reading is programmed using

//looking for where the array starts, from the last position of cursor cursor=indexOf(cursor,"="); //number of arrays to read is known beforehand, structure of each array is known beforehand //and I made a function which reads arrays, values like null, strings, numbers, nested arrays //the function returns the array which is written, containing exactly the written values

If RegExp is going to be an easier solution than what I am using (indexOf(cursor,",") and substr(cursor,presumed length) approach) then I will start learning it immediately. It'll be a replacement of the older approach that I took.

"TACOS blah blah 42 woop FOO BAR ding dong".match(/[a-z0-9]+/g);

Returns ["blah","blah","42","woop","ding","dong"]? Not sure what concatenation does or / does of /g does.

Alright, I'll get to learning. Last question: by Java Console you mean this?

Response to The Flash 'Reg' Lounge 2014-01-09 11:02:07


At 1/9/14 10:00 AM, kkots wrote:
[A-Z]+
The plus sign... its purpose is undefined for me. Yet. *puts the link to the book into bookmarks*

I meant to explain what the plus sign is doing in that post, but it slipped my mind. I explained it in my post that directly follows. If you plop that into a console with and without the plus sign what it's doing will be immediately obvious.

You can paste both of these into a JavaScript console to see the difference:

"hello world".match(/[a-z]/g); "hello world".match(/[a-z]+/g);
At 1/9/14 10:00 AM, kkots wrote: Well, for now the reading is programmed using

//looking for where the array starts, from the last position of cursor
cursor=indexOf(cursor,"=");
//number of arrays to read is known beforehand, structure of each array is known beforehand
//and I made a function which reads arrays, values like null, strings, numbers, nested arrays
//the function returns the array which is written, containing exactly the written values

That's pretty much an ideal situation for using regular expressions.

At 1/9/14 10:00 AM, kkots wrote: If RegExp is going to be an easier solution than what I am using (indexOf(cursor,",") and substr(cursor,presumed length) approach) then I will start learning it immediately. It'll be a replacement of the older approach that I took.

Just bear in mind that regular expressions can only match patterns that are regular, which basically means there aren't exceptions. So long as what you are matching is consistent you won't have any problem. An example of something that is not consistent, and therefore cannot be parsed with regular expressions, is HTML. That's because there are so many different ways to write HTML elements that are all valid:

<!DOCTYPE HTML> <strong>hello world</strong> <input type="text">

All HTML elements are enclosed in <> brackets, which is consistent, but what goes inside those brackets is very much not consistent in any way, so you cannot reliably parse HTML with regular expressions.

However, what slugrail is doing is perfectly fine because there are only two ways for his input data to be formatted, and there are no exceptions to either of those two ways, which makes it a regular pattern.

At 1/9/14 10:00 AM, kkots wrote:
"TACOS blah blah 42 woop FOO BAR ding dong".match(/[a-z0-9]+/g);
Returns ["blah","blah","42","woop","ding","dong"]? Not sure what concatenation does or / does of /g does.

The two forward slashes is just telling JavaScript that the text inside them is a regular expression (it's the most common syntax for regex). Just like how using two quotation marks tells it that the text inside is a string. The "g" is a flag (the thing I mentioned in my note at the bottom of my post) that stands for "global". It means it will match as many times as it can. If you were to remove that it would only match once.

At 1/9/14 10:00 AM, kkots wrote: Alright, I'll get to learning. Last question: by Java Console you mean this?

I didn't mean specifically that, but that will work just fine. I prefer using the JavaScript console that comes with web browsers since you can easily access it by just pressing F12. I don't like Chrome, but I find it has the best console and debugger.

Also don't confuse Java and JavaScript. They are different beasts entirely. :)

Response to The Flash 'Reg' Lounge 2014-01-09 11:27:32


At 1/9/14 11:02 AM, Diki wrote: Just bear in mind that regular expressions can only match patterns that are regular, which basically means there aren't exceptions.

That means it is impossible (or at least extremely difficult) to write if/else branching logic within a RegExp in situations when a pattern can have significant variations that each needs to be dealt with in a different way.
For example, in my situation I don't know if the array being parsed is going to contain a number, a null or a nested array inside one of its indexes.
However, since the match method of String class returns an array of strings, I could determine whether an element is null, a number or a nested array with a simple analysis of the first few characters of the string from the result. Then I could run match for nested arrays and get further data out of them, while null and number would already be the finished results.

I didn't mean specifically that, but that will work just fine. I prefer using the JavaScript console that comes with web browsers since you can easily access it by just pressing F12.

Yep, found it. Seems a bit too advanced, since the match command is the only Javascript command that I know at this moment. Hm, I might as well test it directly in Flash, right while working there. The tool to help write RegExp seems more helpful.

Also don't confuse Java and JavaScript. They are different beasts entirely. :)

Right!

I really would like to thank you, Diki, for explaining this.
You are truly the wisest and the most mature programmer that I know on these forums. And the most helpful.
I just can't thank you enough. I store some of your forum posts that I find especially wonderful. You're like a superhero to me.

Response to The Flash 'Reg' Lounge 2014-01-09 12:50:59


These last few posts felt very strange to me, and here's why:
I wanted to make a post about useful websites that we're using because I've been using regexes a lot and use the gskinner utility a ton.

so, yeah. You guys read my mind :P

anyway, what useful sites do you have?
http://gskinner.com/RegExr/ - for making regexes, amazing utility that shows you every step of your regex
http://prefixr.com/ - in case I somehow get stuck with making cross-browser CSS, I use this to do it for me and format everything nicely
http://randomkeygen.com/ - used for random keys whenever I use internal encryption of some sort
http://gskinner.com/talks/quick/ - I look at this every now and again when I feel like optimizing my AS3 stuff


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to The Flash 'Reg' Lounge 2014-01-09 23:33:01


Egg, you don't look ANYTHING like your icon. I've had this mental image of you actually looking like paper mario, but my dreams have been crushed by the reality of one of your yt videos. I don't look like mine either, but I doubt people think I'm a soy sauce package.

little do they know...

Response to The Flash 'Reg' Lounge 2014-01-10 02:32:34


At 1/9/14 11:33 PM, MSGhero wrote: I don't look like mine either, but I doubt people think I'm a soy sauce package.

You'd be gravely disappointed to find out that I am not a Warcraft 3 lich.
Nor do I look like one.

Response to The Flash 'Reg' Lounge 2014-01-10 08:05:58


At 1/9/14 11:27 AM, kkots wrote: That means it is impossible (or at least extremely difficult) to write if/else branching logic within a RegExp in situations when a pattern can have significant variations that each needs to be dealt with in a different way.

Yeah, it's impossible to use logic like that in regular expressions. It's just not the way that they were intended to be used. If/else logic implies that something is being done (i.e. if this then do this) but regular expressions themselves aren't doing anything. Think of it kinda like a variable: you can't put if/else logic in a variable, but you can use a variable in if/else logic.

At 1/9/14 11:27 AM, kkots wrote: For example, in my situation I don't know if the array being parsed is going to contain a number, a null or a nested array inside one of its indexes.

Well if data you're matching against consistent delimiters you can just use regex to pull out each element, and then use ActionScript to determine what the data is. For example if you have this:

"hello world", 42, null, 1234, "butts", "fat people", 1.34

You can use regular expressions to pull out the text in-between the commas using something like this:

([^,]+)(?:, )?

Which will capture any text that is not a comma that is followed by either ", " (i.e. a comma and a space) or followed by nothing (i.e. the last element in the array). Here's an example of it working in Python.

Of course there is the obvious problem that that means you cannot use a comma in any of your strings. That's just the limitation of regular expressions. If you want to be able to use a delimiter like that, and be able to include the delimiter in string elements, then you have no choice but to tokenise the data and parse it that way.

I also didn't include the [] brackets since including them in the data would make this pretty much impossible (removing those from your input data is pretty straight-forward anyway).

At 1/9/14 11:27 AM, kkots wrote: I really would like to thank you, Diki, for explaining this.
You are truly the wisest and the most mature programmer that I know on these forums. And the most helpful.
I just can't thank you enough. I store some of your forum posts that I find especially wonderful. You're like a superhero to me.

You're welcome, buddy. I aim to please. :)

P.S.
I totally don't look like Bruce Campbell or Ashley Williams (assuming anyone even knows what my avatar is from).

Response to The Flash 'Reg' Lounge 2014-01-10 09:24:19


At 1/10/14 08:05 AM, Diki wrote: I totally don't look like Bruce Campbell or Ashley Williams (assuming anyone even knows what my avatar is from).

I saw an ad or trailer for evil dead 4 a while ago, and I'm like, "Wait, diki is in this?"

Response to The Flash 'Reg' Lounge 2014-01-10 10:20:38


At 1/10/14 08:05 AM, Diki wrote: Which will capture any text that is not a comma that is followed by either ", " (i.e. a comma and a space) or followed by nothing (i.e. the last element in the array). Here's an example of it working in Python.

I see. I sort of got an idea, which I'll express in the end of my post.

Of course there is the obvious problem that that means you cannot use a comma in any of your strings.

I think there's a workaround. In my AS2 code there are no spaces after commas. It means that every comma is always surrounded by two quotation marks in the array. If, say, there was a comma inside one of the strings, it wouldn't be surrounded by two quotation marks, ever. That simply wouldn't happen, because strings are supposed to be dialogue responses, and I do not write dialogue responses with commas not followed by spaces inside them.
Another problem are quotation marks inside strings, written like \". For ex

string="Robot says: \"Hello world!\"";

But then again, in dialogue responses there won't be quotation marks which go immediately after a comma, without a space after it. It means that the delimiter is "," and the array begins and ends with ".

I also didn't include the [] brackets since including them in the data would make this pretty much impossible (removing those from your input data is pretty straight-forward anyway).

Cutting out a piece of string between those brackets to apply RegExp on it should suffice. But then I'll have to perform the cutting using indexOf and substr. Which I'm already doing. Like, from the start of the sub-project (the game is the project, editor is sub-project).

Now, the idea. I've noticed that in our As3: Main thread there is no tutorial about regular expressions. And you've just written a huge detailed explanation of them.
Soooo....

Response to The Flash 'Reg' Lounge 2014-01-10 12:29:33


At 1/10/14 09:24 AM, MSGhero wrote: I saw an ad or trailer for evil dead 4 a while ago, and I'm like, "Wait, diki is in this?"

I'm actually looking forward to the Army of Darkness sequel. The Evil Dead remake took itself way too seriously, which isn't in the spirit of Evil Dead (even though Sam Raimi genuinely tried to make a serious film the first time). Seemed to me that they just wanted to cash in on the Evil Dead name. Then again, Sam Raimi produced that one, so I dunno.

At 1/10/14 10:20 AM, kkots wrote: I think there's a workaround. In my AS2 code there are no spaces after commas. It means that every comma is always surrounded by two quotation marks in the array. If, say, there was a comma inside one of the strings, it wouldn't be surrounded by two quotation marks, ever.

Ahh, okay. I get what you're doing now. That actually makes things quite easy, since you can just use some esoteric punctuation as the delimiter instead of the comma. Just pick something that you know will never, ever be used in dialogue, such as a tilde or grave accent, and use that as your delimiter. Using the grave accent, for example, could simply be done like so:

"Monkeys are scary"`42`"Boner patrol"

And the regex I posted before barely needs to be changed:

([^`]+)`?

Same Python example as before but using the grave accent.

At 1/10/14 10:20 AM, kkots wrote: Cutting out a piece of string between those brackets to apply RegExp on it should suffice. But then I'll have to perform the cutting using indexOf and substr.

You should only need substr(), since the brackets only exist at the beginning and end of the string. So you should just need a substring that is 1 to length-1.

At 1/10/14 10:20 AM, kkots wrote: Now, the idea. I've noticed that in our As3: Main thread there is no tutorial about regular expressions. And you've just written a huge detailed explanation of them.

I could do that. It's been a couple years since I've written AS3, so I would need a quick refresher on the syntax, but I might end up writing another tutorial for that thread. Who knows?

Response to The Flash 'Reg' Lounge 2014-01-10 12:46:46


At 1/9/14 11:33 PM, MSGhero wrote: Egg, you don't look ANYTHING like your icon. I've had this mental image of you actually looking like paper mario, but my dreams have been crushed by the reality of one of your yt videos.

People actually watch my shitty YT videos?!
:P

That's why I wanted my YT icon to have a face. People personify the text they're reading, and it's easier to do when that text has a face attached to it. I can more easily connect with and talk to people when the media with which i'm talking to them has a face. It also helps get the ball rolling for more and better comments because people like talking to people, not blocks of text.

This helps me out a lot because comments improve search ranking and overall help me improve my content.


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to The Flash 'Reg' Lounge 2014-01-10 13:20:05


At 1/10/14 12:29 PM, Diki wrote: Ahh, okay. I get what you're doing now. That actually makes things quite easy, since you can just use some esoteric punctuation as the delimiter instead of the comma.

That's exactly the idea. Although you interpreted it a bit wrong. I work with only 3 different kinds of arrays: the first kind may contain only numbers. The second kind may contain nulls, numbers and nested arrays. The third kind contains only strings. And all these arrays are written in a .AS file (in a plain text file) that I am parsing. The .AS file is actually working code which is supposed to be compiled by Flash, so I must not replace commas with grave accent.
In the file, I need to find the character from which every array starts, and find the character on which the array ends. Then I need to cut out space in between start and end (the array's brackets) and apply RegExp on it.
The array which contains strings will have

delimiter="\",\"";

And the text file will look like

array1=["Prepare to meet your ancestors!","What \"ancestors\" are you talking about, huh?","string3","etc"]; array2=[1,null,[1,2,3],7,null,null];

So I'll need to first find where array1 starts and ends, then cut out a piece of it and use RegExp on it

var start:uint=textFile.indexOf("["); var end:uint=textFile.indexOf("]",start); var piece:String=textFile.substring(start+2,end-1); //piece will look something like Prepare to meet your ancestors!","What \"ancestors\" are you talking about, huh?","string3","etc //the delimiter is "," var result:Array=piece.split("\",\"");

oops, I accidentally did it without using RegExp.

I could do that. It's been a couple years since I've written AS3, so I would need a quick refresher on the syntax, but I might end up writing another tutorial for that thread. Who knows?

Well, your code with tacos

trace("TACOS blah blah 42 woop FOO BAR ding dong".match(/[a-z0-9]+/g));

works in ActionScript 3 without any modifications.
But the tutorial would be more about explaining how RegExp works, what are its limitation, strong points, etc. To test it out in AS3 match and trace are good.

Response to The Flash 'Reg' Lounge 2014-01-10 13:36:52


actually, now i'm having problems with regex. It doesn't make sense to me that this doesn't work, i'm not sure what i'm doing wrong :/

been using RegExr's replace method to parse out all the groups

regex: ^(?:.*?)(?:[\.|//]*)(.*?)$

list of crap:
../../../me/test/blah.txt
/../../../me/test/blah.txt
./../../../me/test/blah.txt
/./../../../me/test/blah.txt
../me/test/blah.txt
/../me/test/blah.txt
./../me/test/blah.txt
/./../me/test/blah.txt
/me/test/blah.txt
me/test/blah.txt
/./me/test/blah.txt
./me/test/blah.txt
=
t../../../me/test/blah.txt
t/../../../me/test/blah.txt
t./../../../me/test/blah.txt
t/./../../../me/test/blah.txt
t../me/test/blah.txt
t/../me/test/blah.txt
t./../me/test/blah.txt
t/./../me/test/blah.txt
t/me/test/blah.txt
tme/test/blah.txt
t/./me/test/blah.txt
t./me/test/blah.txt

in all cases, group[1] should be in the format:
me/test/blah.txt

basically i'm trying to strip out any ../ or ./ from the string


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to The Flash 'Reg' Lounge 2014-01-10 13:51:22


Because you're not escaping the period/elipse, which is part of the regular expression syntax:

"./../../../me/test/blah.txt".replace(/\.?\.\//g,"");

Response to The Flash 'Reg' Lounge 2014-01-10 13:58:35


At 1/10/14 01:20 PM, kkots wrote: var start:uint=textFile.indexOf("[");
var end:uint=textFile.indexOf("]",start);
var piece:String=textFile.substring(start+2,end-1);
//piece will look something like
Prepare to meet your ancestors!","What \"ancestors\" are you talking about, huh?","string3","etc
//the delimiter is ","
var result:Array=piece.split("\",\"");

Problem with that is if you use it on an array that contains an array your end position will return the index of the first ] bracket that it finds, which will be the closing bracket for the nested array, despite you using the opening bracket of the non-nested array (if that makes sense).

One way you could do it is to parse it in reverse (i.e. pull out the nested array first), which could be done by finding the index position of the last [ bracket, and the index position of the first ] bracket, which will be your nested array.

I'm also a little bit pre-occupied at the moment, so I can't really go into more depth than that, but I won't be busy in about 2 hours from now.

At 1/10/14 01:20 PM, kkots wrote: Well, your code with tacos

trace("TACOS blah blah 42 woop FOO BAR ding dong".match(/[a-z0-9]+/g));

works in ActionScript 3 without any modifications.

That's because I JavaScript and ActionScript are both dialects of , so it's common for code to be interchangeable between the languages. I also like to give practical examples of AS3 features, so that's what I would need to brush up on AS3 syntax for.

Response to The Flash 'Reg' Lounge 2014-01-10 13:59:29


At 1/10/14 01:51 PM, Diki wrote: Because you're not escaping the period/elipse, which is part of the regular expression syntax:

I thought I was?

^(?:.*?) - should match whatever's at the beginning of the string that's not a . or / literal
(?:[\.|//]*) - should match all . or / literals
(.*?)$ - should match everything else at the end of the string, which is what I want

yours seems to work fine, thanks, I'm just not quite sure what I did wrong.


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to The Flash 'Reg' Lounge 2014-01-10 14:08:07


At 1/10/14 01:59 PM, egg82 wrote: I thought I was?

You were, I'm just a meat-head and can't read. :)

Anyway the actual reason it wasn't working is because of the end anchor that you included. If you remove it your regex works just fine. Off the top of my head I can't see precisely why the end anchor is making that happen, but once I'm not busy I can look into it. It's probably something quite simple.

Response to The Flash 'Reg' Lounge 2014-01-10 15:02:25


At 1/10/14 02:08 PM, Diki wrote: Anyway the actual reason it wasn't working is because of the end anchor that you included.

Maybe http://www.regular-expressions.info/anchors.html
It says some languages have ^ and $ refer to start and end of the string.
And it also mentions some multiline mode which needs to be turned on using \m
Just blindly poking at things