Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Parsing -- Split of a string?

Posted on 2003-02-20
3
Medium Priority
?
128 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
  • 3
3 Comments
 
LVL 85

Expert Comment

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

Expert Comment

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

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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

572 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