Regular expression – you need to know the logic behind several regular expressions

I have a code as

$wrk = OC192-1-1-1;

@temp = split (/-/, $wrk);

if ($temp1[3] =~ /101 || 102 /)
{
print " yes";
} else {
print "no";
}

Output:

yes 

I need to know why this is printing. I know that regular expressions | OR operator support. But I need to know why || gives "yes" as output

This is because || makes the regular expression match successfully by always matching anything.

So it basically Matches any of the following $temp1 [3] (does not exist)

>"101"
>""
>"102"

I add double quotes Just to explain.

I have a code as

$wrk = OC192-1-1- 1;

@temp = split (/-/, $wrk);

if ($temp1[3] =~ /101 || 102 /)
{
print "yes";
} else {
print "no";
}

Output:

yes

Need to know why this is printing yes. I know that regular expressions | OR operator support. But need to know why || gives "yes" as output

This is because || makes the regular expression match successfully by always matching anything.

So it basically matches any of the following One matches $temp1 [3] (does not exist)

>"101"
>""
>"102"

I added double quotes just for explanation.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5459 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.