Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^7: regex match unicode characters in ascii string

by poj (Abbot)
on Jan 27, 2017 at 21:00 UTC ( [id://1180500]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^8: regex match unicode characters in ascii string
by 3dbc (Monk) on Jan 27, 2017 at 21:35 UTC
    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

      What do you get if you print your string with Data::Dump like this

      #!perl use strict; use HTML::Entities; use Data::Dump 'pp'; my $string = decode_entities( "Role: Role Name▼▼Profile: Unnecessary_Extra_Stuff"); pp $string;
        Thanks for all the help Monks.

        This worked for me... (taken out of context, it's part of a much larger script...)

        ${$ref}{$k}{'DIRTYDATA'} =~ tr/\x09\x0A\x0D\x20-\x7E/ /c; while ( ${$ref}{$k}{'DIRTYDATA'} =~ /(Group|Role[\s2]*)\:\s(\w ++\s\w+)\s*/g ){ ${$ref}{$k}{$1} = $2; } print "\n\nThis is the group: " . ${$ref}{$k}{Group}; print "\nThis is the Role: " . ${$ref}{$k}{Role} . "\n\n";
        - 3dbc

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1180500]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-24 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found