|
|
| Think about Loose Coupling | |
| PerlMonks |
Matching escaped quoted stringsby jmcnamara (Monsignor) |
|
| on Feb 19, 2004 at 17:40 UTC ( #330280=perlquestion: print w/ replies, xml ) | Need Help?? |
|
jmcnamara has asked for the
wisdom of the Perl Monks concerning the following question:
Here is a problem that may be harder or simpler than it looks. The task is to extract double quoted strings from another string. For the string
the matched strings would be "foo" and "bar" including the quotes. The thing that makes this a little tricky is that double quotes in the quoted string are escaped using a pair of quotes. I think this escape format comes from Basic. Thus, the string " He said "maybe" " would be escaped as follows:
This leads to some nice pathological cases such as '""""""""""' and '" """&" """' Here is a test framework if you care to bend your brain to this puzzle. I'll post my own answer later.
Problem. Write a function find_quote() which takes a string and adds <> around the double quoted strings. For example
Double quotes within the string are escaped as a pair of double quotes. The quotes will always be balanced. Apart from double quotes there can be any arbitrary characters before or after the strings. The test below should demonstrate the types of string to expect.
--
Back to
Seekers of Perl Wisdom
|
|
||||||||||