
2teez
Novice
Aug 24, 2013, 8:04 AM
Post #2 of 7
(3252 views)
|
Hi, Using only this data you posted, the following could do it for you:
$str=~s{\s+?\((.+?)\)(\s+)?}{ '$1' }g; You can at the top of your script to see what was going on. Hope this helps. *Update* In case you want the explanation of your regex you could see this module: YAPE::Regex::Explain. Below is how the above regex is explained:
this 'is' a test of <a te(st)ing> of a 'type' The regular expression: (?-imsx:\s+?\((.+?)\)(\s+)?) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- \s+? whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the least amount possible)) ---------------------------------------------------------------------- \( '(' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- .+? any character except \n (1 or more times (matching the least amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- \) ')' ---------------------------------------------------------------------- ( group and capture to \2 (optional (matching the most amount possible)): ---------------------------------------------------------------------- \s+ whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- )? end of \2 (NOTE: because you are using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \2) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
(This post was edited by 2teez on Aug 24, 2013, 8:19 AM)
|