Regex for this

I want to catch something like this : .V30M ( 1'b1 )

PADRV30MA0 IOP057_VOUT3_OUT ( .IO ( VOUT3_OUT ) , .V30M ( 1'b1 ) ) ;

PADRV15MA0 IOP059_VOUT15_OUT ( .IO ( VOUT15_OUT ) , .V15M ( 1'b1 ) ) ;

PADHOGOA1 IOP064_VREFLB ( .IO ( VREFLB ) , .MONI ( SYNOPSYS_UNCONNECTED_17 ) ,

.MON_D ( px_IOP064_VREFLB_MON_D ) , .R0T ( 1'b1 ) ,

.IO1 ( SYNOPSYS_UNCONNECTED_18 ) ) ;

Can anyone tell me the possible regex for this?

I tried :

\.V30M\s+\(\s+\S+\s+\)

&

\.V30M\ \( \S+ \)

But in perl i get output as :

.V30M ( 1'b1 ) ) ;

why this extra 2 characters in the end

Hello utkarshkhanna44,

In case you want to get everything(NOT exactly 30M) then you could try following.

awk -F, 'match($2,/\.[0-9a-zA-Z]+ \( [^)]* \)/){print substr($2,RSTART,RLENGTH)}'   Input_file

In case you want to have only 30 M string as per your shown logic then you could try following once.

awk -F, 'match($2,/\.[a-zA-Z]+30M \( [^)]* \)/){print substr($2,RSTART,RLENGTH)}'   Input_file

Thanks,
R. Singh

your regex is not matching : .V30M ( SYNOPSYS_UNCONNECTED_99 ) ) ;

--- Post updated at 08:43 AM ---

I want regex of something like this : .V30M ( anything )

You did not say what you did in detail.
If you do a substitution, then you need to capture everything in the RE that you want to substitute! A trailing .* might do it.

You mention perl. In perl you can (group) a part of the RE, and refer the matched part as $1 in a substitution string and afterwards.

perl -nle '/(\.V30M\s*\(\s*\S+\s*\))/ and print $1'

The and means "continue if true". In a logical and the RHS is only evaluated (i.e. run) if the LHS is true.

BTW a substitution in perl is less elegant:

perl -nle 's/.*(\.V30M\s*\(\s*\S+\s*\)).*/$1/ and print'

This is quite similar to (GNU-)sed:

sed -nr 's/.*(\.V30M\s*\(\s*\S+\s*\)).*/\1/p'
1 Like

I am actually searching for this substring .V30M and storing the whole string if the string is like this : .V30M ( any_thing_here )
The above Regex matches .V30M ( 1'b1 ) but doesn't find this : .V30M ( SYNOPSYS_UNCONNECTED_99 )

Certainly because it's not in the input.?

echo "something .V30M ( SYNOPSYS_UNCONNECTED_99 ) something" | perl -nle '/(\.V30M\s*\(\s*\S+?\s*\))/ and print $1'
.V30M ( SYNOPSYS_UNCONNECTED_99 )

Here I have made the + non-greedy with a following ? .