On Mon, 10 Aug 2009 16:43:21 -0700 (PDT), mud_saisem <> wrote:
>On Aug 11, 5:19*am, s...@netherlands.com wrote:
>> On Sun, 9 Aug 2009 15:25:24 -0700 (PDT), mud_saisem <mud_sai...@hotmail.com> wrote:
>> >Hi There,
>>
>> >Could anybody please let me know how I would be able to extract the
>> >words that have a = in the middle and print the whole word out. Also I
>> >will never know how many : and in the word either.
>>
>> >eg: "This is a example item, order=TEST:ITEM:123 on shelf
>> >shelf=1:4:23:f"
>>
>> >output: order=TEST:ITEM:123
>> > * * * * * shelf=1:4:23:f
<snip>
>>
>> My opinion on this group (or any group) is that using real world examples
>> reap the most reward.
>>
>> -sln
>
>Sln,
>
>Thanks for your comments.
>
>The examples that I have given are based on problems that I can not
>figure out and need help with.
>
>If I put in real world example as you call it, It would still make no
>sense to you or any other person reading this discussion. I ask for
>help on what I need to resolve my issue and never intended this to be
>a learning curve for pupils.
>
>Personally I don't see what the issue is as others have managed to
>give very good and efficient solutions to the problem that I face.
>
>But I your point is taken !
>
>I am still very new at perl, and in the future I will put in better
>examples WHERE POSSIBLE.
Sorry, I didn't mean it as criticism, just to be a little helpful.
It doesn't help you to put up example text that you want to
parse with a regular expression, in a waterred down, pristeen way.
This is your example:
"This is a example item, order=TEST:ITEM:123 on shelf
shelf=1:4:23:f"
But you state you really want this form "=::" to be plucked out using \w=[\w:]
Itself, its being used as a form and form delimeter. And thats ok.
In a real example though, its not that simple. The form itself must be
seperately delimited to avoid collision. That makes it more difficult.
And \w as a form delimeter rarely does what you think it does.
It leaves out many possible valid characters. You can class characters
that you would would like to INCLUDE as your only form delimeter, but it
is better to class NOT characters in the form, then surround the form itself
with delimeters.
Since the delimeters are simple whitespace, you could (as someone mentioned)
split on \s+, then analyse the form itself.
Or you could do, in a real sence, something like below.
-sln
use strict;
use warnings;
my $string = "begi-n==TEST:ITEM:b123
begin2=='TEST':ITEM:b-123 This is a example item, order=TEST:ITEM123:test= on shelf
'shelf'=1:4:*23::f";
while ($string =~ /(?:^|(?<=\s))([^\s:=]+)=+([^\s=]+)(?=\s|$)/g)
{
print "$1 = @{[split /:+/, $2]}\n";
}
__END__
begi-n = TEST ITEM b123
begin2 = 'TEST' ITEM b-123
'shelf' = 1 4 *23 f
|