Paul
Thu, 10 May 2001 14:29:40 -0700
--- Carl Rogers <[EMAIL PROTECTED]> wrote: > Not having Perl up and running, would this work with the > parenthesis?? > $temp = ~ m/PT[\(]*(\w+)[\)]*/; > $value = $1; > I'm sure there is a one-line answer, but I'm too new to know. > > At 05:13 PM 5/10/2001 -0400, Gross, Stephan wrote: > >I want to match the following: > >1) the letters "PT" > >2) a space or nothing > >3) a word that may or may not be in parentheses or even not exist > >and return item #3 (which may be null) > >Example: > >PT (XYZ) or PT XYZ or PTXYZ or PT > >should return "XYZ" except the last case, which should return "". > > > >I can do everything except the parentheses case. Any ideas? my($ans) = $temp =~ /PT\s?\(?(\w*)/; \s? is zero-or-one whitespace character \(? is zero-or-one left paren \w* is zero-or-more "word" characters (letters,numerals,underscores) $ans has parens around it to give the match assignment a list context, so that it returns the pattern matched. =o) ===== print "Just another Perl Hacker\n"; # edited for readability =o) ============================================================= Real friends are those whom, when you inconvenience them, are bothered less by it than you are. -- me. =o) ============================================================= "There are trivial truths and there are great Truths. The opposite of a trival truth is obviously false. The opposite of a great Truth is also true." -- Neils Bohr __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/