0
votes

I have a Tcl variable with the following contents:

m_hscaclbmbmmer_v11_2 
m_letmmcbterbox_v1_2 
m_osbbbbcmd_v16_0 v_proc_ss_v1_0 
m_rmgbbb2cycrcb_v17_4
m_nscalbbbcer_v8_2
m_smpte2mbbc022_m12_rx_v2_3
m_smpte2m02cm2_12_tx_v2_2
m_smpte20m2mcm2_56_rx_v5_4
m_smpte202m2_c56_tx_v4_0 
m_smpbbbte_sdbbci_v3_0
m_smpte_uhdmsdic_v1_2
m_tmmmc_v6_4 
m_tpmmmg_v17_1
m_vcresamcpler_v1_2
m_vid_mminc_axi4s_v14_1
m_voip_femcc_rx_v11_3
m_voip_fmbmecc_tx_v1_2
m_vscalebcr_v1_4
m_ycrcb2bncrgb_v7_4
mid_phy_cnmcbmbontroller_v2_2
mibmmbbo_v3_4
miterbcbmbi_v9_4
madc_wicbmbz_v3_4
mambmbuic_v12_2  mvxfftc_v9_4

The last name, mvxfftc_v9_4, needs to be changed into microsemi.com:ip:mvxfft:9.4, the same needs to be done to all names. How do I do that?

2
hi all i need convert each core name , as in last two line and store them in a single variable what i am thinking is to concatenation microsemi.com and then do string pattern matiching with changing verison to unserscore to . - user864752
You want to change all occurrences of mvxfftc_v9_4? - Dinesh
hi dinesh , my question i want change each core , for example - user864752
m_hscaclbmbmmer_v1_2 into microsemi.com:ip: m_hscaclbmbmmer:1.4 in simliar fashion i need to change all core into similar fashion i hope u got it ,if not please let me know - user864752
I tried to clean up your question to be legible. I suppose the strong text part shouldn't be there, and that the occurrences of names on the same line should be on different lines, please edit to reflect your intents. - Peter Lewerin

2 Answers

1
votes

The problem is slightly under-specified, but I'm assuming that you are taking each name like this (marking the parts to be extracted):

mvxfftc_v9_4
^^^^^^   ^ ^

and transforming that to (marking the parts inserted):

microsemi.com:ip:mvxfft:9.4
                 ^^^^^^ ^ ^

That's not too hard with regsub, and since we're changing a well-formed word to a well-formed word, we can probably just use it directly on the variable as string processing without needing to map it over the list explicitly:

set changed [regsub -all {\y(\w+)\w_v(\d+)_(\d+)\y} $original {microsemi.com:ip:\1:\2.\3}]
# \y is a beginning-or-end-of-word anchor
# \w means any alphanumeric-or-underscore
# \d means any digit
# \1, \2 and \3 are substituted by the parenthesised matches

There's a limit to the complexity of mappings that you can do this way, but maybe this will be enough.

0
votes

Maybe you could try (assuming your list of names is in name):

foreach name $names {
    puts microsemi.com:ip:[regsub {_v(\d)_(\d)$} $name {:\1.\2}]
}

It's not pretty, but it does what you seem to be saying that you want done.

If you want a list instead of a printout, you could use this (Tcl 8.6 or later, leaves result in result):

set result [lmap name $names {
    lindex microsemi.com:ip:[regsub {_v(\d)_(\d)$} $name {:\1.\2}]
}]

or this (most versions):

set result {}
foreach name $names {
    lappend result microsemi.com:ip:[regsub {_v(\d)_(\d)$} $name {:\1.\2}]
}

Documentation: foreach, lappend, lindex, lmap, lmap replacement, puts, regsub, set

On regular expression writing:

There are also a few sites dedicated to regular expressions for various programming languages: a Google search should help you.