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

  1. two (or more) single quotes
  2. two (or more) full stops
  3. single quote, full stop
  4. full stop, single quote
  5. ...
In other words any sequence of full stops and single quotes without other characters in between.

You can therefore search for this rejection pattern and accept all lines which are not matched by the rejection pattern.

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.
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.

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


In reply to Re: About regular expressions by CountZero
in thread About regular expressions by nagalenoj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.