inherit
125435
0
Jun 1, 2013 7:46:21 GMT -8
Lugubrious
I love arrays...
790
May 2008
lugubrious
|
Post by Lugubrious on Apr 26, 2010 17:50:44 GMT -8
Could someone explain the RegExp Object? I keep reading the tutorial and I still can't wrap my mind around it. Preferably explain using examples; I don't like conceptual things as much as practicality. Thank you so much to whichever person explains this. I catch on to things easily, usually.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Apr 26, 2010 18:09:23 GMT -8
First of all, are you just trying to grab stuff and save it from Proboards or from somewhere else? Assuming it's for Proboards, you would use something like this:
<script type="text/javascript"><!-- var td=document.getElementsByTagName('td'); for(t=0; t<td.length; t++){ if(td.item(t).innerHTML.match(/(.?+)\ some words after what you're looking for/i){ var amount = RegExp.$1; document.write(amount); } } //--></script>
So the most usual RegExp to use is (.?+)\ or (\d+)\ (correct me on the proper use of the d one) The (\d+)\ is used to grab numbers, and the (.?+)\ is used for everything else.
If you need more examples, just look in some PM bar codes, and such.
|
|
inherit
125435
0
Jun 1, 2013 7:46:21 GMT -8
Lugubrious
I love arrays...
790
May 2008
lugubrious
|
Post by Lugubrious on Apr 26, 2010 18:12:44 GMT -8
Thank you very much! That helped a lot. I'll go check those out and hash it out.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Apr 26, 2010 18:14:09 GMT -8
|
|
inherit
125435
0
Jun 1, 2013 7:46:21 GMT -8
Lugubrious
I love arrays...
790
May 2008
lugubrious
|
Post by Lugubrious on Apr 26, 2010 18:37:40 GMT -8
That tutorial is absolutely fantastic. It is helping fill in the gaps that come from teaching yourself everything. ^.^ Thank you so much. If I have more questions while I play around with it, I'll post 'em here. For some reason the tutorials I've used for a while now seem to make that very confusing. I'll follow the tutorial for a bit.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Apr 27, 2010 15:59:15 GMT -8
Yeah, that's where I finally figured out RegExp.. everything else I got by myself.
|
|
inherit
24252
0
Aug 1, 2023 15:01:24 GMT -8
coolcoolcool
When the world says, "Give up," Hope whispers, "Try it one more time."
2,148
May 2004
coolcoolcool
|
Post by coolcoolcool on May 7, 2010 20:20:46 GMT -8
Something else you might want to know. The letters i and g after the second / are modifiers. The i stands for case-insensitive and the g means global or more than once (keeps searching after first occurence. The regular expressions part of it can get rather complicated, so the best method is usually to use a resource (like a tutorial) to look back on when doing them .. or any programming for that matter. Good luck!
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,022
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on May 7, 2010 22:12:14 GMT -8
I haven't read the entire thing but it looks pretty thorough. I however would like to point out a tiny error in the regex section which might give those trying to learn the wrong idea...
It's a subtle difference but in this particular case the ? is functioning as a greed modifier not an optional. The greed modifier basically says stop as soon as you find a match for the pattern rather than the usual behavior of extending the match until it can go no farther.
For example if that regex was run against the following sentence:
The dog is commonly referred to as man's best friend. The loyalty displayed by this animal is said by some to be superior to any human friend they've ever had.
With the greed modifier, the match would stop at the first period, without the greed modifier it would continue on to the second period. The decision to include it or not would depend on how much data you wish to capture and not whether that data is optional. If there was a question mark to the right of the closing parenthesis (.+?)? then that would be an optional for what was contained in the parentheses.
|
|