in reply to Re: how to split a string at [ ?
in thread how to split a string at [ ?

Hello!

The text before the equal sign can differ from BCInletTemperature. It can be another word. But the word will be always low/capital charaters without a blank.


Can I get this with the above too?

Regards, blaui

Replies are listed 'Best First'.
Re^3: how to split a string at [ ?
by Corion (Patriarch) on Jul 06, 2018 at 13:44 UTC

    Yes, see perlre on how "alternations" work:

    $temp =~ /(BCInletTemperature|someOtherTemperature|aThirdTemperatu +reName) = ([\d.]+)\[C\]/ or die "Invalid temperature format in '$temp'"; my( $temperatureType, $temperatureValue ) = ($1,$2);

    But maybe you want a more generic parser that will capture any word on the left hand side of the "=" sign and any number on the right hand side. Then you can use the \w character class or the [A-Za-z] character class (again, see perlre) for matching any word on the left hand side:

    $temp =~ /(\w+) = ([\d.]+)\[C\]/ or die "Invalid temperature format in '$temp'"; my( $temperatureType, $temperatureValue ) = ($1,$2);