in reply to perl regex
I can offer one additional comment. The /g is unnecessary for your example. (The anchors ^ and $ each refer to a single place in the string.) It may be needed if your real data is a multi-line string, but then you would have other issues to consider.
For your example, you can use:
use strict; use warnings; my $row = 'We_need_feed'; my($first_word, $last_word) = $row =~ /^(\w+)_.*_(\w+)$/; print $first_word, ' ', $last_word;
|
|---|