Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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.

Comment on Re: Parsing a Word placed between special characters
Select or Download Code
Replies are listed 'Best First'.
Re^2: Parsing a Word placed between special characters
by Laurent_R (Monsignor) 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]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2016-02-10 23:40 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (354 votes), past polls