in reply to About regular expressions
is there any other better regex which will work instead of the given one?Of course, "There Is More Than One Way To Do It"!
It all depends how you define your matches. It seems you want to reject all lines with a sequence of
You can therefore search for this rejection pattern and accept all lines which are not matched by the rejection pattern.
Is this regex better? That --again-- depends. If your "match" pattern is rather complicated or the strings to match are long, it can take a while to run and sometimes the "rejection" pattern is simpler as it will stop as soon as one of the rejection cases is found.use strict; use warnings; while (<DATA>) { if (/['.]{2,}/) { print "Rejected: $_"; } else { print "Accepted: $_"; } } __DATA__ St.John's high school. A. B. C. school. Institute of management. oxford university. A.B.C college. Ragu ram's college of technology. A..B.C college. St.John''s high school. St.John'.'s high school.
In case of doubt, just profile your code and see what performs best.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|