in reply to Re^4: regex match unicode characters in ascii string
in thread regex match unicode characters in ascii string

Are you running the code I posted ?. If not can you please post the string that is not working so I can replicate the error.

poj
  • Comment on Re^5: regex match unicode characters in ascii string

Replies are listed 'Best First'.
Re^6: regex match unicode characters in ascii string
by 3dbc (Monk) on Jan 27, 2017 at 20:53 UTC
    Yes, I'm using your code. like i said it works, but $2 only has the role name, not the group name. ideally I'd like $2 to have the group name and $3 to have the role name.

    I updated the original post. The string gets messed up when you post it with < code > tags.

    my $string ="Group: Group Name▼▼Role: Role Name"

    Thanks!
    - 3dbc

      I thought you said in an earlier reply you wanted an array. If you want a hash ref then try this, the while loop matches both values

      #!perl use strict; use HTML::Entities; use Data::Dump 'pp'; my $string = "Group: Group Name&#9660;&#9660;Role: Role Name"; $string = decode_entities($string); my $href={}; while ( $string =~ /(Group|Role)\:\s+([\x00-\x7f]*)/g ){ $href->{$1} = $2; }; pp $href; print "Role = $href->{'Role'}\n"; print "Group= $href->{'Group'}\n";
      poj
        Getting closer... Thank you! Sorry if I'm not clear enough, there's a lot of strings I'm matching against, but what I want remains the same. I want the group and role names in the hash. For instance, I used a string like this:

        $string = "Role: Role Name▼▼Profile: Unnecessary_Extra_Stuff";

        but it returned:

        This is the Role Name:Role Name▼▼Profile Name: Unnecessary_Extra_Stuff

        FYI, here's my code snippet:
        while ( ${$ref}{$k}{'DIRTYDATA'} =~ /(Group|Role)\:\s+([\x00-\x7f]*)/g + ){ ${$ref}{$k}{$1} = $2; } print "\n\nThis is the Group Name: " . ${$ref}{$k}{Group}; print "\nThis is the Role Name: " . ${$ref}{$k}{Role};


        I only want it to return Group or Role names, not Profile names and no extended ascii characters.

        I did mention an array before, but it's storing fine in my HoH which I'm getting out of a fetchall hashref from DBI, so storage really isn't the problem, the problem is only matching role group names in these dirty little strings.

        Thanks.
        - 3dbc