Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Parsing a Word placed between special characters

by kennethk (Abbot)
on May 01, 2013 at 18:19 UTC ( #1031625=note: print w/replies, xml ) Need Help??

in reply to Parsing a Word placed between special characters

Welcome to the Monastery. In the future, please wrap input in <code> tags so it doesn't get mangled. Note how chunks of your post got linkified.

The basics of your question are documented in Extracting matches in perlretut. The only trick, assuming you mean to be using [ and ] as delimiters, is that these characters have special meaning in regular expressions, and thus must be escaped. Your regular expression might look something like /\[(.*?)\]/.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: Parsing a Word placed between special characters
by Laurent_R (Canon) on May 02, 2013 at 11:52 UTC

    Again assuming the explored string is in the $_ special variable, the words between square brackets can be retrieved as follows:

    $name = $1 if /\w+\[(\w+)\]\w+/;
Re^2: Parsing a Word placed between special characters
by Anonymous Monk on May 02, 2013 at 09:40 UTC
    Thanks to everyone who responded. The query was in fact obscure since I didn't use the <code> tag. Please find the query in a proper format below.

    I have a file called names.txt with the following content

    I was trying to extract the initials placed between special characters  [ and ] and output this to a new file initials.txt as



    I hope that I have clarified the question. Thanks once again to those who guided me the correct regex. Regards, PS.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031625]
NodeReaper waits for the new pizza guy, again

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2018-03-25 03:52 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (300 votes). Check out past polls.