Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex on command line 1

Status
Not open for further replies.

thedaver

IS-IT--Management
Jul 12, 2001
2,741
US
Can someone explain my error?

Code:
 perl -e '$foo="baz.com"; $bar=$foo; $bar=~s/\.{2,3}$//; print "$foo\n"; print "$bar\n";'

Should print:
baz.com
baz

instead prints
baz.com
baz.com

Thanks!

D.E.R. Management - IT Project Management Consulting
 
$bar =~ s/^(\w+)\.\w$/$1/ should do it. Your expression is expecting to sub 2 or 3 dots for nothing
 
readey, your solution didn't right straight away, but it made me realize my error. This worked:

s/\.\w{2,3}$//

Thanks!
D.

D.E.R. Management - IT Project Management Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top