Channing
Channing

Reputation: 1

Finding a string with regex

I'm looking to match "Serial Number:" and then store the value in a variable. So far I have this but for some reason it is not finding it.

set value [regexp -line {^\s*Serial Number: (.*)$} $expect_out(buffer) store]

This is the output, I want to match Serial Number and store the value in a variable:

Contents of Main Board IDPROM
    Assy, NetNet6300     
    Serial Number:                  091245076951       
    BoardRev:                       03.00         
    PCB Family Type:                Main Board    
    Options:                        0                     

Upvotes: 0

Views: 34

Answers (1)

sniperd
sniperd

Reputation: 5274

What you should do is the following:

^\s*Serial Number:[^\d]*(\d+)

Which looks to be like this in your example:

set value [regexp -line {^\s*Serial Number:[^\d]*(\d+)} $expect_out(buffer) store]
  • [^\d]* means any amount of non-numbers (including none)
  • (\d+) will match any non-zero amount of numbers

I also like h20000000's comment but I prefer to use the negative character class of what I'm looking to capture, either will work!

Upvotes: 1

Related Questions