0

Here's the string I'm using and the display of this string can be rearrange in any other and in my case, I'm only interested in getting the first parenthesis text and putting the remaining text on its on line..

For example,

(test network) or test(section memory) or test(section storage)

Ideal output:

test section network
or test(section memory) or test(section storage)

Here's the perl code I attempt to use to accomplish this goal.

    while(<readline>)
    {
        $_ =~ s/^\(test (.*)\)(.*)/test section $1\n$2/gi;
    }

The output does not match the ideal output I'm looking for.

3 Answers 3

2

perreal answer seems good, but here is another solution using ungreedyness (using ? after the *)

s/^\(test (.*?)\)\s*(.*)/test section $1\n$2/gi
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

s/^\(test ([^)]*)\)\s*(.*)/test section $1\n$2/gi

Comments

1

your expression is being too greedy, the first bit (test (.*)) matches up the the last ) on the line, so dosn't work.

Make the expression non-greedy

s/^\(test (.*?)\)(.*)/test section $1\n$2/gi

probably don't need the g (global) modifier either.

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.