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).