fork(1) download
  1. #!/usr/bin/perl
  2. use feature "say";
  3. use strict;
  4. use warnings;
  5.  
  6. my $content = "I am trying to capture this 1910.1024, this 1910.1024(a) and this 1910.1024(a)(3).";
  7. if($content =~ m/([0-9]{4})\.([0-9]{4})/) {
  8. $content =~ s{
  9. ([0-9]{4}) # $1 = First 4 digits
  10. \. # Dot
  11. ([0-9]{4}) # $2 = Second 4 digits
  12. (?:\((\w+)\))? # (, $3 (first optional "word"), )
  13. (?:\((\w+)\))? # (, $4 (second optional "word"), )
  14. }{
  15. "<!!uf dp_ecfr29 29cfr$1x$2 #29cfr$1x$2" .
  16. (defined($3) ? "z-$3" : "") . (defined($4) ? "-$4" : "") .
  17. ">$1.$2" .
  18. (defined($3) ? "($3)" : "") . (defined($4) ? "($4)" : "") .
  19. "</a>"
  20. }gxe;
  21. say "$content\n";
  22. } else {
  23. say "Error";
  24. }
  25.  
  26.  
Success #stdin #stdout 0.01s 5504KB
stdin
Standard input is empty
stdout
I am trying to capture this <!!uf dp_ecfr29 29cfr1910x1024 #29cfr1910x1024>1910.1024</a>,  this <!!uf dp_ecfr29 29cfr1910x1024 #29cfr1910x1024z-a>1910.1024(a)</a> and  this <!!uf dp_ecfr29 29cfr1910x1024 #29cfr1910x1024z-a-3>1910.1024(a)(3)</a>.