Extracting matching string, else null

What''s the most concise script expression that will return the match of regexp EEE in string SSS, else if there is no match, null?

Like $if($regexpmatch(SSS,EEE),$regexp(SSS,EEE) , ) if $regexpmatch was available :slight_smile:

Thanks.

If match then result is 1, if no match then result is 0.
Example:
$if($neql('20090808',$regexp('20090808','8',)),1,0)

DD.20090808.1929.CEST

$if($neql('20090808',$regexp('20090808','8',)),1,0)

To meet the requirement that way, it seems we would need

$if($neql(SSS,$regexp(SSS,EEE,RRR)),$regexp(SSS,EEE,RRR),)

Is there a solution that requires less duplication?

I think it should be read ...
$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),)

DD.20090809.1655.CEST

I think it should be read ...
$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),)

Aha, yes - thanks.

So is this "the most concise script expression", to do think? I would really like one without duplication, since SSS and sometimes EEE can be long expressions.

Note fails in the case

$if($neql(,$regexp(,'^$',)),1,0)

(returns 0) though this is not a problem to my application.

... and this can also happen ...
$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),SSS)
... if someone wants to leave the original string untouched.

DD.20090809.1716.CEST

Surely $regexp itself is sufficient for that, since it leaves the original string untouched if no match.

The second regexp replace can only work when the first regexp catches a match, otherwise the if clause will return nothing, which would be able to distort the current field value, if this function starts from/with the value of the current field.

DD.20090809.2028.CEST

Agreed, but what I am saying is surely

$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),SSS)

and

$regexp(SSS,EEE,RRR)

give the same result.

Yes, in this case there is no need to detect possible matching previously.

DD.20090910.0538.CEST