Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ukma!husc6!genrad!news From: news@genrad.UUCP (Network News) Newsgroups: comp.lang.perl Subject: Re: a regular expression question Keywords: rexp match Message-ID: <37163@genrad.UUCP> Date: 28 May 90 14:37:42 GMT References: <1336@taurus.BITNET> Reply-To: rep@thor.genrad.COM (Pete Peterson) Organization: GenRad, Inc., Concord, Mass. Lines: 37 along the line (TAURUS.BITNET), so I have to resort to posting. From: rep@genrad.com (Pete Peterson) Path: rep In article <1336@taurus.BITNET> writes: >When I use the matching operator on something like > >"cp" =~ /cp\s*@*\s*/ > >it matches, and I think it shouldn't because as far as I understand, >only expressions of the form "cp\s*@*\s*" (that is - >cp\s@\s ) should have matched the pattern, and >"cp" does not even include the '@' ! Even more confusing is the fact that >"cp aa@bb cc" matches (which I expected), but $+ = "cp " !!! > I think that your only problem is that you're confusing "*" in regexps with "*" in shell syntax. In regular expressions, RE* means ZERO OR MORE occurrences of the regexp RE. To indicate "anything" corresponding to "*" in shell syntax, you need ".*" where "." is a regexp which matches "anything" and "*" means zero or more occurrences. In your example (cp aa@bb cc), "cp " was matched by "cp\s*" AND also by "cp\s*@*\s*" which couldn't match any longer string because there was nothing to match the "a". > >Could anyone help? I want only "cp\s@\s" to >match. > I think that what you really want is "cp\s.*@.*\s.*" wherein "cp" matches "cp" each "\s" matches some whitespace, "@" matches "@" and each ".*" matches an arbitrary string of characters. Let me know if this isn't clear and I'll try again. pete peterson rep@genrad.com {decvax,linus,wjh12,mit-eddie,masscomp}!genrad!rep