Why is this regex not working!
sub FindInHorizontalRegion { print "Inside FindInHorizontalRegion"; my ( $self,$element1,$element2,$duration,$threshold) = @_; my ($xcoord1,$ycoord1, $xcoord2, $ycoord2); my $regex1 = '(.*?)\:(.*?)'; print "Damn the element1 is $element1 \n"; if ( $element1 =~ m/$regex1/g ) { print "Inside wait for image \n"; my $region = $self->WaitForImage( $element1, $duration ); $xcoord1 = $region->getX; $ycoord1 = $region->getY; print "The coordinates of element1 are $xcoord1, $ycoord1 +\n"; } else { print "Inside wait for Text \n"; my $region = $self->WaitForText( $element1, $duration ); $xcoord1 = $region->getX; $ycoord1 = $region->getY; print "The coordinates of element1 are $xcoord1, $ycoord1 \n"; + } if ( $element2 =~ m/$regex1/g ) { my $region = $self->WaitForImage( $element2, $duration ); $xcoord2 = $region->getX; $ycoord2 = $region->getY; print "The coordinates of element2 are $xcoord1, $ycoord1 \n"; } else { my $region = $self->WaitForText( $element2, $duration ); $xcoord2 = $region->getX; $ycoord2 = $region->getY; print "The coordinates of element2 are $xcoord1, $ycoord1 \n"; } my ($x1,$y1,$x2,$y2) = $self->GetHorizontalCoord($xcoord1,$ycoord1 +,$xcoord2,$ycoord2,$threshold); print "The horizontal coordinates are $x1,$y1,$x2,$y2 \n"; print "The element1 is $element1 \n"; if ( $element1 =~ m/$regex1/g ) { print "To check for iImage"; my $region = $self->WaitForImageInROI($element1,$x1,$y1,$x2,$y +2,$duration); return ($region); } else { print "To check for tText"; my $region = $self->WaitForTextInROI($element1,$x1,$y1,$x2,$y2 +,$duration); return ($region); } } sub GetHorizontalCoord { print "Inside GetHorizontalCoord"; my ( $self,$xcoord1,$ycoord1,$xcoord2,$ycoord2,$threshold ) = @_; my $width = $self->GetDeviceProperty('Width'); my $height = $self->GetDeviceProperty('Height'); my $x1 = 0; my $x2 = $width; my $y1 = $ycoord1 - $threshold ; if ($y1<0) { $y1 = 0; } my $y2 = $ycoord2 + $threshold; if ($y2 > $height) { $y2 = $height; } return ($x1,$x2,$y1,$y2); }

The input in the script goes something like this

my $region = $object->FindInHorizontalRegion('SETTINGS:Flight','SETTIN +GS:Tick','1000',10);

I need to pass SETTINGS:Flight to WaitForImageInROI, instead, the if condition is failing and it is invoking WaitForTextInROI. The problem is that in these lines,

my ($x1,$y1,$x2,$y2) = $self->GetHorizontalCoord($xcoord1,$ycoord1,$xc +oord2,$ycoord2,$threshold); print "The horizontal coordinates are $x1,$y1,$x2,$y2 \n"; print "The element1 is $element1 \n"; if ( $element1 =~ m/$regex1/g ) { print "To check for iImage"; my $region = $self->WaitForImageInROI($element1,$x1,$y1,$x2,$y +2,$duration); return ($region); } else { print "To check for tText"; my $region = $self->WaitForTextInROI($element1,$x1,$y1,$x2,$y2 +,$duration); return ($region); }

though element1 is SETTINGS:Flight, the else condition is getting executed. While the same regex works for the previous if conditions, I'm not able to understand why it does not work here.

Thanks.

In reply to Regex not working by Perllace

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.