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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selectively editing input value - Help Needed.

Status
Not open for further replies.

millimeter

Programmer
Mar 30, 2002
12
US
I am able to remove various elements, including combinations of occurrences. Example:
$someFileName ="text.txt";
$someFileName =~ s/(.txt)//g ; # remove ".txt"
print "$someFileName";
Output is "text"

However I have been unable to get working anyway of removing unknown values from before an occurrence.
Example:

$someFileName ="text.txt";
$someFileName =~ s/([What ever I need to do here])//g ; # remove "text"
print "$someFileName";
Output is ".txt"

Thanks for your help!

Millimeter.
 
The following should do the trick:

$someFileName ="text.txt";
$someFileName =~ s/.*(\.\w+)$/$1/;

.* - matches 0 or more of any character
\. - literal .
\w+ - matches 1 or more word character (0-9,a-Z)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top