---
title: "perl 正则表达式"
author: "luogen33"
date: "2011-11-25T14:04:00Z"
tags: []
categories: ["编程语言"]
slug: "perl"
draft: false
lastmod: "2011-11-25T14:04:00Z"
id: 1278275
url: "https://luogen33.iteye.com/blog/1278275"
---

正则表达式:
$scalarName =~ s/a/b; # substitute the character a for b, and return true if this can happern
$scalarName =~ m/a; # does the scalar $scalarName have an a in it?
$scalarName =~ tr/A-Z/a-z/; # translate all capital letter with lower case ones, and return ture
if this happens
$scalarName !~ s/a/b/; # substitute the character a for b, and return false if this indeed
happens.
$scalarName !~ m/a/; # does the scalar $scalarName match the character a? Return false
if it does.
$scalarName !~ tr/0-9/a-j/; # translate the digits for the letters a thru j, and return false
if this happens.
--------------------------------------------------------------------------------------------------

#!/usr/bin/perl
$mt="abcdeFGhigk";
#匹配
if ($mt =~ m/Fg/i){
   print  "匹配--it is matched ! \n";

}
# 替换
if ($mt=~s/FG/fg/){
   print "替换-- $mt \n";
}
#转换
if ($mt =~ tr///){
   print "转换--$mt \n";
}