Avatar of jdg3
jdg3

asked on 

Need a Regular Expression.

I have thousands of COBOL Copybooks where I need to make modifications to various number of PICS.  I am looking for a regular expression that will replace the following '9' to an 'X'  


From:

~PIC~9(N).

to

~PIC~X(N).


where the '~' is a VARIABLE number of spaces, and where 'N' is a VARIABLE number of digits. The period '.' at the end of the line is required on the line.  The parentheses '( )' are also required as part of the PIC line.

Finally,  I do not want to modify any PIC 9's that are COMP or COMP3.  For instance, the following is not a candidate for modification:

~PIC~9(7)~COMP3.

I am new to regular expressions, and do not know how to handle the parentheses and periods, inasmuch as they are actually part of the expression.  The type of regular expression can be Perl or Unix.

Thanks in advance.
Regular ExpressionsPerlAlgorithmsCOBOL

Avatar of undefined
Last Comment
mjcoyne
Avatar of ozo
ozo
Flag of United States of America image

s/(\sPIC\s+)9(?=\(\d+\)\./${1}X/;
Avatar of ozo
ozo
Flag of United States of America image

sorry
 s/(\sPIC\s+)9(?=\(\d+\)\.)/${1}X/;
Avatar of nedfine
nedfine
Flag of India image

this pel script will replace 9(04) to X(04) if the usage is not comp or comp3

$d = "01 ar    pic    9(04) usage is comp";
if($d =~/\S+\s+9\(\d+\).*comp/)
{
   #do nothin;
}
else
{
   if($d =~/\S+\s+9\(\d+\)/)
   {
      #print "helloo";
      $d =~s/9\(/X\(/;
   }
}
print $d;
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of nedfine
nedfine
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
Avatar of mjcoyne
mjcoyne

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Perl
Perl

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects. Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.

26K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo