notjj2 Posted September 10, 2009 Posted September 10, 2009 Hey all,I'm having a bit of trouble with regex and hopefully you can help me out.So the initial string comes in as part of an HTML source... "3. third<br> 4. fourth<br> 5. fifth<br> 8. eighth<br> 9. ninth<br> 10. tenth<br> 12. twelfth <br> 14. fourteenth"From here I'm trying to pull out all the words... however, it's pulling out "br" as well...Here's the regex I'm using. $aResults = StringRegExp($allText, "[[:alpha:]]+", 3)Just to make sure I'm getting my point across.... the array my autoit code retuns is: third br fourth br fifth br eighth br ninth br tenth br twelfth br fourteenthI'm pretty sure the results I'm looking for have something to do with the conditionals in RegEx.... but after tons of reading I still can't figure it out.
Hawkwing Posted September 10, 2009 Posted September 10, 2009 (edited) This works. #include<array.au3> $array = StringRegExp("3. third<br> 4. fourth<br> 5. fifth<br> 8. eighth<br> 9. ninth<br> 10. tenth<br> 12. twelfth <br> 14. fourteenth", "[0-9]{1,2}. ([a-z]{5,10})<br>", 3) _ArrayDisplay($array) Edited September 10, 2009 by Hawkwing The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
notjj2 Posted September 10, 2009 Author Posted September 10, 2009 I'm trying to make sure I don't get the numbers in there... but I could see "([a-zA-Z]+)<br>" helping... I'd just have to trim the last 4 characters for every element in the array... thanks.
Hawkwing Posted September 10, 2009 Posted September 10, 2009 You didn't test the code. The numbers and <br> are just to make sure its getting the right string. The only thing it puts into the array is what is in the group. Groups are defined by parentheses, and if the flag is 1 or 3 it captures the groups and puts them into an array. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
Hawkwing Posted September 10, 2009 Posted September 10, 2009 To learn the basics of stringregexp, you should read neogia's guide, helped me a lot a couple weeks ago. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now