Home: Perl Programming Help: Regular Expressions:
Urgent help needed



arokiamary
New User

Sep 6, 2011, 9:05 PM


Views: 6442
Urgent help needed

Hi

I have to compare two txt files contain more than 500 lines using perl script.

In file A "Regulation" and a number will come in each line end.
file B "RG" and a number will come in each line last end.

Below two lines sample for this.I need to ignore if "Regulation 2" in File A and "RG 2" in File B
i tried with pattern matching i am not getting


Optometrists and Opticians (simple) Regulations, Cap. 500A, RG 2
OPTOMETRISTS AND OPTICIANS (SIMPLE) REGULATIONS, Cap. 500A, Regulation 2

$vldbString =~ s/Regulation\s+(\d+)\s*$/RG $1/g; --- tried not working
$vldbString =~ s/Regulation/N/RG;

could you please help me to solve this issue.

Regards
Mary


daptal
Novice

Sep 7, 2011, 5:24 PM


Views: 6419
Re: [arokiamary] Urgent help needed

Can you please a few lines of the input file and the desired output file aswell.


wickedxter
User

Sep 7, 2011, 5:43 PM


Views: 6418
Re: [arokiamary] Urgent help needed

 
s/// desnt ignore it replaces whats matches in the first // and replaces it wil the next // so s/a/B/ will replace a with B, so are you trying to capture everything before the RG 2 and Relegation? if so you'll need to rethink your regex to either capture from the beginning of the string or you change your code to whats below and it will remove whats matched by the regex.


Code
 
#captures the Reg. and RG 2 and removes them
$vldbString =~ s/Regulation\s+\d+\s*//;
$vldbString =~ s/RG\s*\d*//;

#capture everything before regulations
$vldbString =~ /^(.*)Regulations|REGULATIONS/;
[\code]


(This post was edited by wickedxter on Sep 7, 2011, 5:43 PM)