• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

text manipulating

Let`s say I have a script that haves  the following code:

$str=<<'fH';
 some jalla
some jalla filename="test.zip"
Here is
the
Cool stuff
that I wanna grab

---some more jalla
jalla jalla
jalla
fH


Now, I wana grab the stuff between
filename="test.zip"
and ---some more jalla
and store it in a $jalla2
And the filename, and the jalla before filename  will change so I wanna have a code that takes all the code after filename* (that takes the code on the next line)

Hope u understand what I ment.
 
0
govinje
Asked:
govinje
  • 5
  • 5
  • 2
1 Solution
 
thoellriCommented:
$str=<<'fH';
 some jalla
some jalla filename="test.zip"
Here is
the
Cool stuff
that I wanna grab

---some more jalla
jalla jalla
jalla
fH
($filename,$jalla2)=($1,$2) if($str =~ /filename="([^\"]+)".(.*).--some more jalla/ms);
print "Filename is: $filename\nJalla2 is: $jalla2\n";

???
  Tobias
0
 
govinjeAuthor Commented:
Tnx! IT worked almoast perfect!!
But it didn`t work 100 %.
I tried with this code:
$str=<<'fH';
 some jalla
some jalla filename="test.zip"
Here is
the
Cool stuff
that I wanna grab

---some more jalla
jalla jalla
jalla

some jalla
some jalla filename="test.zip"
Here is
the
Cool stuff
that I wanna grab

---some more jalla
jalla jalla
jalla

fH


And then it printed out to times.
now I just wanna print out the first thing..  I don`t care about the stuff below the first --some more jalla
Is it possible to to this?


Tnx
0
 
ozoCommented:
/filename="([^"]+)".(.*?).--some more jalla/ms);
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
thoellriCommented:
Ozo's solution is correct. Change it in the script above (well, you actually just need to change the greediness of the .*) and you should be set.

0
 
govinjeAuthor Commented:
Wow the code is nearly perfect now..
But if the stuff is written like this:

$str=<<'fH';
 some jalla
some jalla filename="test.zip"
Here is
the
Cool stuff
that I wanna grab

---some more jalla THIS STUFF CHANGES
jalla jalla
jalla

fH
It don`t grab the cool stuff, because the line ---some more jalla changes..
I mean, it would be great if I had a code that took from between filename*
next line, until it found ---some more*
So it didn`t care about what it found after the ---some more jalla.
I tried with ---some more jalla*/ms
but it did not work as expected...

0
 
ozoCommented:
/filename="([^"]+)".(.*?)\n--some more/s
0
 
govinjeAuthor Commented:
Sorry ozo, am I very bad when I say it`s not perfect yet..
Sorry!
But if the stuff  is this:
$str=<<'fH';
 some jalla
some jalla filename="test.zip"
Here is
the
Cool stuff
that I wanna grab

---some more jalla THIS STUFF CHANGES
jalla jalla
jalla

---some more jalla THIS STUFF CHANGES
fH

Then it prints out the cool stuff and the ---some more jallaa THIS STUFF CHANGES
and jalla jalla jalla.

And I want it to stop at the first ---some more jalla

Tnx for u`re patient`s!

0
 
ozoCommented:
/filename="([^"]+)".(.*?)\n---some more/s
0
 
govinjeAuthor Commented:
Eh.. I have noticed that it was missing one - but that was not the problem..
It prints out until the next ---some more jalla
U see?
0
 
ozoCommented:
$str=<<'fH';
 some jalla
some jalla filename="test.zip"
Here is
the
Cool stuff
that I wanna grab

---some more jalla THIS STUFF CHANGES
jalla jalla
jalla

---some more jalla THIS STUFF CHANGES
fH
($filename,$jalla2)=($1,$2) if( $str=~/filename="([^"]+)".(.*?)\n---some more/s );
print "Filename is: $filename\nJalla2 is: $jalla2\n";

prints:
Filename is: test.zip
Jalla2 is:
Here is
the
Cool stuff
that I wanna grab

0
 
govinjeAuthor Commented:
Sorry Ozo, the stuff u posted worked with that code..
I tried to change it like this..
And I thought it could work..

$str=<<'fH';
some jalla
some jalla filename=test.zip begin
Here is
the
Cool stuff
that I wanna grab

---some more jalla THIS STUFF CHANGES
jalla jalla
jalla

---some more jalla THIS STUFF CHANGES


fH

 
($filename,$jalla2)=($1,$2) if( $str=~/begin([^"]+).(.*?)\n---some more/s );
print "Filename is: $filename\nJalla2 is: $jalla2\n";

Why does not this work???
I only removed the "" at the filename-thing. I just wanna have a general code that I can use notmather what the text are..
Tnx again!

0
 
ozoCommented:
($filename,$jalla2)=($1,$2) if( $str=~/filename=(.+?).begin.(.*?)\n---some more/s );
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 5
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now