0
$\begingroup$

How do I get the card number and device number alone from this string by using a regular expression to parse it?

Here's the string

 ~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: usb device [usb device], device 0: Audio [Audio Input]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

I need to parse the "card 0" and "device 0". I just need the values 0,0

Any advice will be appreciated.

$\endgroup$
3
  • 1
    $\begingroup$ Are you using Mathematica for this task? What code have you tried? $\endgroup$ – m_goldberg Oct 22 '15 at 9:35
  • 1
    $\begingroup$ To all, I don't see how closing this as needing more info can be justified when it has an accepted answer. $\endgroup$ – m_goldberg Oct 22 '15 at 15:07
  • $\begingroup$ FWIW: you can execute shell commands from within Mathematica: ReadList["!arecord -l", "String"]. $\endgroup$ – J. M.'s torpor Oct 22 '15 at 15:59
3
$\begingroup$

You don't need regular expressions.

text = 
"~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: usb device [usb device], device 0: Audio [Audio Input]
  Subdevices: 0/1
  Subdevice #0: subdevice #0"

StringCases[text, {"card" | "device"} ~~ Whitespace ~~ d : (DigitCharacter ..) -> d]

{"0", "0"}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.