5

I am using this regular expression to find patterns in a genome.

$string =~ /(?i)a+t?|(?i)t+/g

To make the output easier to read I would like to modify it so it capitalizes anything it matches that is 4 to 7 characters long. Also it should not mess up the $+[0] or $-[0] variables.

the way i do the output is to get a sub-string from the larger string file based on the '$+[0]' and '$+[0]' i don't want to print out the regex matches i am printing out huge strings of correctors and i want the matches to stand out.

if you really need to see the code I'm working on you can get it here

Orion
  • 207
  • 2
  • 9

1 Answers1

11

With appropriate tests (for your match and for length (character groups with quantifiers like {4,7} are probably needed), without example content this is left to you) you could use an eval substituton s/(match)/uc($1)/eg which would take the matched string and make it uppercase then replace the match with the replacement.

As always read more at perldoc perlre perldoc perlreref perldoc perlretut

As a sidenote, I have always wondered if Genomes are a good candidate for Regexp::Grammars?

Joel Berger
  • 20,180
  • 5
  • 49
  • 104
  • 8
    No need for an "eval substitution". The replacement part of s/// is double-quotish so you can use a backslash escape without the need for s///e: s/(match)/\U$1/g – tadmc Jun 28 '11 at 17:00
  • Wow, I can't believe it's that easy. – felwithe Feb 23 '19 at 19:08