in reply to Re: Extracting names from string
in thread Extracting names from string

What does "m!/(.*?)|!;" actually do? Arnt you missing the ending "/" Basically what I need is for it to grab all data within these characters starting with "/" and ending with "|". Im not sure if I can extract the data using reg expression. Thanks again, Jack

Replies are listed 'Best First'.
Re^3: Extracting names from string
by ikegami (Patriarch) on Feb 08, 2005 at 16:26 UTC

    /.../, m/.../, m#...#, m!...! and so on are all equivalent. The character following the m will be used to delimit the regexp.

    Use
    ($reversed_name) = $string =~ m/\/(.*?)\|/;
    if you prefer. It means the same thing, but it's not quite as readable.

    foreach $string ( "s005219/Doe John|John.Doe\\", "s0052194/Doe Thomas|Thomas.Doe\\", ) { ($reversed_name) = $string =~ m!/(.*?)\|!; print($reversed_name, "\n"); } # Prints # ====== # Doe John # Doe Thomas

    Alternatively,

    foreach $string ( "s005219/Doe John|John.Doe\\", "s0052194/Doe Thomas|Thomas.Doe\\", ) { if (m!/(.*?)\|!) { print("$1\n"); } }