how to set variable to results of regex in one line
Posted: Mon Jun 08, 2009 3:12 pm
Hi -- this is actually more of a perl question, but thought someone here might still know --
I want to be able to perform a regex match and set the results into a variable, but in one easy step rather than doing what I usually do, i.e.
if ( $matchstr=~ /(regex)/ ) {
$result = $1
}
I figure there is a better way than this right? I know I can do this with search/replace, but would like to preserve the original string.
...sorry if I'm missing something obvious....
I want to be able to perform a regex match and set the results into a variable, but in one easy step rather than doing what I usually do, i.e.
if ( $matchstr=~ /(regex)/ ) {
$result = $1
}
I figure there is a better way than this right? I know I can do this with search/replace, but would like to preserve the original string.
...sorry if I'm missing something obvious....