?
Solved

Parsing -- Split of a string?

Posted on 2003-02-20
3
Medium Priority
?
127 Views
Last Modified: 2010-03-05
3 inquiries -- same category:

What if I wanted do a similar split as you mention Ozo, however I want everything between K & NOT L(~L)
or M & NOT Z or V & NOT B

thus:
AFDFSDFKLSDFSDFKVDFDSFSDFMZSDFDFSMRDFSDFMY gives the following splits:
AFDFSDFKLSDFSDFK
VDFDSFSDFMZSDFDFSM
RDFSDFM
Y

Also, a quick question. If I have a string with each line having a return(newline) at the end:
KAJFDKSJFSDKLSDFSDFSDF\n
asdfdasfsdafsadfsadfsd\n
asdfasdfasdfdsafasdfasdf\n

and I just want to separate the 1st newline. Thus, the goal - 2 strings:

KAJFDKSJFSDKLSDFSDFSDF\n
&
asdfdasfsdafsadfsadfsd\n
asdfasdfasdfdsafasdfasdf\n

what is the best way to do it.. Is this correct:
($first, $last) = (/\n/, $string)
?


Also, if I just want to parse on the basis of 'K' but keep the 'K' would it be
@words = split(/?<=K/, $string)?

Thanks so much for your help.
0
Comment
Question by:jambalaya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 7990558
$_='AFDFSDFKLSDFSDFKVDFDSFSDFMZSDFDFSMRDFSDFMY';
print join "\n",split/(?<=K)(?!L)|(?<=M)(?!Z)|(?<=V)(?!B)/;
0
 
LVL 84

Expert Comment

by:ozo
ID: 7990581
$string = "KAJFDKSJFSDKLSDFSDFSDF\nasdfdasfsdafsadfsadfsd\nasdfasdfasdfdsafasdfasdf\n";
($first, $last) = $string =~ /(.*\n)(?s:(.*))/;
0
 
LVL 84

Accepted Solution

by:
ozo earned 300 total points
ID: 7990608
#or
$string = "KAJFDKSJFSDKLSDFSDFSDF\nasdfdasfsdafsadfsadfsd\nasdfasdfasdfdsafasdfasdf\n";
($first, $last) = split/$/m,$string,2;
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question