Grey Fox has asked for the wisdom of the Perl Monks concerning the following question:
Hello Fellow Monks;
I'm having a difficult time trying to get REGEX to stop after finding the first occurence of a string. I am extracting title information from an SGML file, and the regex is only returning partial information.
I'm using the following regex.
m/\s(?:-\s)?([\w\s\d()-,]{1,75})<\/title>/ against the following data.<title>GRP -134 - Grinding And Cutting Solution (ACME PR50 - Water Typ +e) </title> <title> GRP-123-1 - Grinding And Cutting Solution (Quakeroat 2780 UTC +- Synthetic Type)</title> <title> GRP-124 - Alkaline Rust Remover Solution</title> <title> GRP-124-1 - Alkaline Rust Remover Solution (Ardvark 185 - Rust + Remover)</title> <title> GRP-124-2 - Alkaline Rust Remover Solution (Ardvark 185L - Rus +t Remover)</title> <title> GRP-124-3 - Alkaline Rust Remover Solution (Bee-Dee J84AL - Ru +st Remover)</title> <title> GRP-124-4 - Alkaline Rust Remover Solution (Mag HD2-202 - Rust + Remover)</title> <title> GRP-124-5 - Alkaline Rust Remover Solution (Turk 4181L - Rust +Remover)</title> <title> GRP-124-6 - Alkaline Rust Remover Solution (Turk 4181 - Rust R +emover)</title> <title> GRP-124-7 - Alkaline Rust Remover Solution (Bee-Dee J84A - Rus +t Remover)</title> <title> GRP-124-8 - Alkaline Rust Remover Solution (Cadilac HTP-1150 - + Rust Remover)</title> <title> GRP-124-9 - Alkaline Rust Remover Solution (Cadilac HTP-1150L +- Rust Remover)</title> <title> GRP-124-10 - Alkaline Rust Remover (Titanium Long Soak)";
Instead of getting "Grinding and Cutting Solution (ACME PR50 - Water Type)", I'm only getting "Water Type)", because of the second occurence of the " - " in the data. I know there is a way to make the regex only see the first occurence and then pass me all of the rest of the text up until </title>.
I've looked at Perlre and http://www.regular-expressions.info/quickstart.html
Thanks. Note: Added more examples
-- Grey Fox
"We are grey. We stand between the darkness and the light" B5
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex only returning partial data
by toolic (Bishop) on Jun 06, 2008 at 17:42 UTC | |
Re: Regex only returning partial data
by throop (Chaplain) on Jun 06, 2008 at 17:54 UTC | |
Re: Regex only returning partial data
by johngg (Canon) on Jun 06, 2008 at 20:48 UTC | |
Re: Regex only returning partial data
by FunkyMonk (Chancellor) on Jun 06, 2008 at 17:40 UTC | |
by Grey Fox (Chaplain) on Jun 06, 2008 at 17:58 UTC | |
by FunkyMonk (Chancellor) on Jun 06, 2008 at 18:11 UTC | |
Re: Regex only returning partial data
by Grey Fox (Chaplain) on Jun 06, 2008 at 20:18 UTC |
Back to
Seekers of Perl Wisdom