gcue Posted January 10, 2019 Share Posted January 10, 2019 hello world i am trying to get the following digits -7.670000 from the following stdout (the first mention of -7.670000 is the one im after): Quote c:\users\smith\desktop\04 Life on Mars-.mp3 Recommended "Track" dB change: -7.670000 Recommended "Track" mp3 gain change: -5 Max PCM sample at current gain: 34042.576896 Max mp3 global gain field: 210 Min mp3 global gain field: 86 Recommended "Album" dB change for all files: -7.670000 Recommended "Album" mp3 gain change for all files: -5 stringbetween might be a little tricky because the numbers vary. i have also tried stringregexp but i am not getting good results either expandcollapse popup#include <AutoItConstants.au3> #include <array.au3> $msg_normal = 0 $mp3gain_dir = "C:\Users\smith\Downloads\mp3gain-win-full-1_2_5" $mp3_path = "c:\users\smith\desktop\04 Life on Mars-.mp3" Local $iPID = Run(@ComSpec & ' /c mp3gain.exe "' & $mp3_path & '"', $mp3gain_dir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = "" While 1 $sOutput = StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf if $sOutput = "" then ContinueLoop ;~ debug($sOutput) $rec_track_db_change = StringRegExp($sOutput, "db change: -([\d]*)", 3) debug($rec_track_db_change) WEnd Func Debug($variable1 = "", $variable2 = "", $variable3 = "", $variable4 = "", $variable5 = "") ;~ #include <array.au3> ;~ $msg_normal = 0 If IsArray($variable1) Or IsArray($variable2) Then If IsArray($variable1) Then _ArrayDisplay($variable1, $variable2) If IsArray($variable2) Then _ArrayDisplay($variable2, $variable1) Else $variable = "" If $variable1 <> "" Then $variable &= $variable1 & @CRLF If $variable2 <> "" Then $variable &= $variable2 & @CRLF If $variable3 <> "" Then $variable &= $variable3 & @CRLF If $variable4 <> "" Then $variable &= $variable4 & @CRLF If $variable5 <> "" Then $variable &= $variable5 & @CRLF $variable = StringStripWS($variable, 2) ClipPut($variable) MsgBox($msg_normal, "Debug", $variable) EndIf EndFunc ;==>Debug as always any help is greatly appreciated!!! Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 10, 2019 Share Posted January 10, 2019 (edited) @gcue \d is a metacharacter, so it doesn't need the square brackets, which are used with ranges, like A-Z, 0-9, and so on. Then, since you need to capture the dot too, you need to specify that in the pattern, and so, you should do something like this: #include <Array.au3> #include <StringCostants.au3> Global $strString = 'Recommended "Track" dB change: -7.670000' & @CRLF & _ 'Recommended "Track" mp3 gain change: -5' & @CRLF & _ 'Max PCM sample at current gain: 34042.576896' & @CRLF & _ 'Max mp3 global gain field: 210' & @CRLF & _ 'Min mp3 global gain field: 86' & @CRLF & _ 'Recommended "Album" dB change for all files: -7.670000' & @CRLF & _ 'Recommended "Album" mp3 gain change for all files: -5"' _ArrayDisplay(StringRegExp($strString, "(?m)(-?\d{1,}\.?\d*)", $STR_REGEXPARRAYGLOBALMATCH)) Comments: Spoiler (?m): option multiline.\d: metacharacter to "capture" a digit ([0-9]);{1,}: quantifier. "Capture" the previous character from 1 to N times;\ : backslash. Backslash is used to treat a metacharacter (the dot) literally;.: metacharacter to "capture" every character except the newline (it does capture the newline when the option ?s is enabled);?: quantifier, lazy. "Capture from 0 to 1 time" the previous character.\d: metacharacter to "capture" digits ([0-9]);*: quantifier. "Capture" the previous character from 0 to N times. Edited January 10, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
gcue Posted January 10, 2019 Author Share Posted January 10, 2019 hmm missing the minus on there (note: sometimes the minus will be there and sometimes it wont) tried plugging in w or W in different spots but getting really weird results thank you very much for your help!! Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 10, 2019 Share Posted January 10, 2019 (edited) @gcue Edited the previous post \w is used when you want to "capture" a word character, which is in the range [a-zA-Z0-9_]; \W is used when you want to capture anything that is NOT a word character. When you need to "capture" digits only, then use \d, and nothing else Edited January 10, 2019 by FrancescoDiMuro Skysnake 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
gcue Posted January 10, 2019 Author Share Posted January 10, 2019 perfect!!! thank you!!! hope you enjoy the rest of your week Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 10, 2019 Share Posted January 10, 2019 @gcue Tank you buddy, you too Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
gcue Posted February 8, 2019 Author Share Posted February 8, 2019 sometimes the result im looking for is in element 3 and sometimes 2. any chance i can get ONLY the resulting digits that is after Recommended "Track" dB change: thanks in advance! Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted February 8, 2019 Share Posted February 8, 2019 (edited) @gcue If you want to get only the digits after the text 'Recommended "Track" dB change: ', just change the SRE pattern to: Recommended "Track" dB change: (-?\d{1,}\.?\d*) Edited February 8, 2019 by FrancescoDiMuro spudw2k 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
gcue Posted February 8, 2019 Author Share Posted February 8, 2019 perfect!!!! thank you again!! hope you have a great weekend Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted February 8, 2019 Share Posted February 8, 2019 @gcue Happy to have helped The same for you! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now