Jump to content

[SOLVED] Bitwise negation with regular expression question


noochies

Recommended Posts

Hello,

I am very baffled with some lines of code from a program I took over that was written by someone else.

Here is the code:

 

my $ext=$file;
$ext =~ /(\..{3,4}$)/;
$ext = $1;
my $documentFormatId = isAllowedExtension($ext);

 

I know that this is ultimately getting the file extension into the $ext variable, but that's as far as I've gotten.

 

I can't figure out what the second line is trying to do. I put in print statements in between each of those lines printing out what the var $ext had in it. After the second line, the var is the same as it was before the second line (it equals $file).

 

I know that the tilde character (~) is the bitwise negation character, but I'm not sure how the regular expression fits into the mix.

Can someone tell me how you bitwise negate a string with a regular expresson involved?

 

This is Perl:

 

### Define the variable
my $ext = $file;
### Run a match
$ext =~ /(\..{3,4}$)/;
### Assign the first capture from the last match
$ext = $1;

NODE                    EXPLANATION

----------------------------------------------------------------------

  (                        group and capture to \1:

----------------------------------------------------------------------

    \.                      '.'

----------------------------------------------------------------------

    .{3,4}                  any character except \n (between 3 and 4

                            times (matching the most amount

                            possible))

----------------------------------------------------------------------

    $                        before an optional \n, and the end of

                            the string

----------------------------------------------------------------------

  )                        end of \1

Well how stupid do I feel?  :-[

 

I apologize about that. This application I adopted has it's front end written in php and the back end written in perl. I guess I got the two temporarily mixed up. WHOOPS.

 

Thanks for all your responses...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.