regular expression meaning

Discussion in 'Perl Misc' started by nicolas-laurent, Apr 20, 2005.

  1. Could you explain to me what this regular expression means

    =~ m,([^;]+);([^\n]+)\n?,g) {

    sub build_rules {
    my $src = get_file_content($rules_spec);
    my %rules;
    while ($src =~ m,([^;]+);([^\n]+)\n?,g) {
    $rules{$1} = $2;
    return \%rules
    nicolas-laurent, Apr 20, 2005
    1. Advertisements

  2. The function parses a string like "rule1;abc\nrule2;def\nrule3;ghi" and
    assigns the rule/value pairs to a hash.

    perldoc perlrequick
    perldoc perlretut
    perldoc perlre
    Gunnar Hjalmarsson, Apr 20, 2005
    1. Advertisements

  3. ^^ ^^^
    ^^ ^^^

    The underlined parts are NOT part of a regular expression.

    m,([^;]+) # any chars that are not semicolon
    ; # required semicolon
    ([^\n]+) # any chars that are not newline
    \n? # optional newline

    ie. Grab 2 chunks of text separated by a semicolon.

    It seems a hokey regexification of a vanilla split():

    split /;/, $somevar, 2;

    Where did you come across that code?
    Tad McClellan, Apr 20, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.