2

I have a string like:

za b c
   x y
   x z
ya b c
   x y
   x z

Now if I split as:

my @lines = split /\n([a-z])/, $input;
my @sorted_lines = sort @lines;

The input line is split into three parts as:

za b c
   x y
   x z

y

a b c
  x y
  x z

Is there a way to split based on newline+somecharacter, but retain that character to the next token ? I mean I want the output to have only two tokens as: 1) za ... and 2) ya ....

2
  • Did you mean [a-z]? Commented Apr 30, 2013 at 7:12
  • ah yes. Thanks. I missed the regex. Commented Apr 30, 2013 at 7:23

1 Answer 1

7

Get the regex to look ahead without capturing with (?=...):

my @lines = split /\n(?=[a-z])/, $input;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.