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

Thanks works well, but is only catching the last occurrence... meaning it only matches the role name, not the group name too. Need it to match both and ignore anything else so that I can update the DBI hashref with this info.
- 3dbc
  • Comment on Re^4: regex match unicode characters in ascii string

Replies are listed 'Best First'.
Re^5: regex match unicode characters in ascii string
by poj (Abbot) on Jan 27, 2017 at 20:48 UTC

    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
      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