Limo has asked for the wisdom of the Perl Monks concerning the following question:

I've been playing around with this for a few hours. I've got the regex that leads up to the beginning of the text that I want to extrapolate. But, I'm stuck once I'm there! I've tried word boundaries, but to no avail. Can anyone shed some light? Here's an example string:
IOS (tm) GS Software (GSR-P-M), Version 12.0(12.3)S, EARLY DEPLOYMENT +MAINTENANCE INTERIM SOFTWARE
What I need to grab:
Version 12.0(12.3)S
I tried using \B to match the whitespace before Version, and \B to specify the ending boundary of "," and (.*?) in between. Obviously, this didn't work for me.

Replies are listed 'Best First'.
Re: Removing a text element from the middle of a string
by merlyn (Sage) on Sep 30, 2000 at 08:41 UTC
    Hmm. If your book told you \B matches whitespace, you'd better get a different book. I'd stick with /(Version.*?),/ as the regex, using $1 as the result.

    -- Randal L. Schwartz, Perl hacker

      You went against your mantra of "down with .*" here... why not advocate using /(Version[^,]*),/ here?

      Update
      Oops, sorry Ovid. I saw it in his favorite nodes list, and thought it was his. Good rant from you. :)

      $_="goto+F.print+chop;\n=yhpaj";F1:eval
        While I will confess that I noticed that merlyn has Death to Dot Star! listed (on his home node) as one of his favorite nodes, I'm actually the one who wrote that and I occassionally get friendly grief from fellow monks for using it. :)

        (Though if merlyn rants against .*, I'd be interested in seeing the link)

        Incidentally, I'd write the regex as follows (assuming that the data is very clean):

        my $result = $1 if $string =~ /,\s([^,]+)/;
        Cheers,
        Ovid

        Update: japhy, it's an easy mistake to make. I just feel proud to have made the list :)

        Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

        Or:
        /(Version.*?*),/
        Note - Depending on the data this may or may not perform worse than the previously suggested
        /(Version[^,]*,/
      Oops. Clearly, I read that wrong! Thanks!
(tye)Re: Removing a text element from the middle of a string
by tye (Sage) on Sep 30, 2000 at 08:41 UTC

    \B is a non-boundary while \b is for boundaries.

            - tye (but my friends call me "Tye")
Re: Removing a text element from the middle of a string
by fundflow (Chaplain) on Sep 30, 2000 at 20:31 UTC
    why not use
    $s=split(/,/, $line)[1];
    or something similar? It seems like this is what you really want.