1

I need to port some Perl code to python, and Im not very familiar with Perl..

if (($fieldsParsed==0)&(/\/\/ address,.*/)) {
                push (@reservedMemoryArray,$_);
                $fieldsParsed = 1;
            }

I need help understanding this regexp. what does the /\/\/ address,.*/ mean? and if this regex matches, the next line is pushed into the array, right?

Thanks

2
  • 2
    The actual regex is \/\/ address,.*. / is most probably the delimiter, which is not needed in Python. I can't read Perl code, though, so I don't know what is happening in your code. Commented Jan 7, 2014 at 8:27
  • 1
    Quite human readable help: tutorialspoint.com/perl/perl_regular_expression.htm Commented Jan 7, 2014 at 8:29

1 Answer 1

3

The meaning of /\/\/ address,.*/:

/           : delimiter
\/\/        : two slashes
 address,   : literally ' address,'
.*          : any char 0 or more times
/           : delimiter

It returns true if the current $_ contains // address, whatever you want.....

Sign up to request clarification or add additional context in comments.

3 Comments

ah, ok. I was not aware of this delimiter syntax in Perl. If I just copy paste this regex into re.match I should remove those?
@WeaselFox: yes you should.
The outer slashes actually mark the match operator. As the doc says: "You can omit the m from m// if the delimiters are forward slashes, but for all other delimiters you must use the m prefix."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.