hmsSurprise Posted April 20, 2007 Posted April 20, 2007 (edited) Regexp, as it has done for 20 years, is beating up on me again. I have the system path value: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PHP;;D:\PHP;D:\MySQL\MySQL Server 4.1\bin. If I find 'C:\PHP' I want to change it to 'D:\PHP' or actually $dvDrive & '\PHP' . Here in my example I see I have the added problem of paths for C and D drives. I was hoping that StringInStr would return a string that I could examine further but since that is not the case I decided to start with StringRegExp. Using the snippet below I cannot get a return value other than 0 from StringRegExp. I am sure it is a simple mistake but I am not seeing it. It also appears that StringInStr does not support wild cards. Is that true? Thanks, jh $regPath = 'HKLM\SYSTEM\CONTROLSET001\CONTROL\SESSION MANAGER\ENVIRONMENT' ;$s = RegRead($regPath, 'Path') ;Line above returns '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PHP;;D:\PHP;D:\MySQL\MySQL Server 4.1\bin' $s = '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PHP;;D:\PHP;D:\MySQL\MySQL Server 4.1\bin' $search = 'D:\PHP' ;'?:\PHP' $match = StringRegExp($s, $search) MsgBox(0,$s, $match) Edited April 20, 2007 by hmsSurprise
Sokko Posted April 20, 2007 Posted April 20, 2007 (edited) Backslash is a special character. If you want to match an actual backslash, you must escape it by using another backslash, as in "D:\\PHP". You are correct in saying that StringInStr only does literal string matching. If you want wildcards, well, that's what StringRegExp is for. Edited April 20, 2007 by Sokko
hmsSurprise Posted April 20, 2007 Author Posted April 20, 2007 Backslash is a special character. If you want to match an actual backslash, you must escape it by using another backslash, as in "D:\\PHP".Thanks, Sokko. I knew it was simple or stupid or both, I should have known better, actually I do or did.As the saying goes: 'Sometimes is better to keep your mouth shut and appear stupid than to open it and remove all doubt'.The would-be scripter needs more starter fluid, another cup of coffee please.jh
EndFunc Posted April 20, 2007 Posted April 20, 2007 Regexp, as it has done for 20 years, is beating up on me again. I have the system path value: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PHP;;D:\PHP;D:\MySQL\MySQL Server 4.1\bin. If I find 'C:\PHP' I want to change it to 'D:\PHP' or actually $dvDrive & '\PHP' . Here in my example I see I have the added problem of paths for C and D drives. I was hoping that StringInStr would return a string that I could examine further but since that is not the case I decided to start with StringRegExp. Using the snippet below I cannot get a return value other than 0 from StringRegExp. I am sure it is a simple mistake but I am not seeing it. It also appears that StringInStr does not support wild cards. Is that true? Thanks, jh $regPath = 'HKLM\SYSTEM\CONTROLSET001\CONTROL\SESSION MANAGER\ENVIRONMENT' ;$s = RegRead($regPath, 'Path') ;Line above returns '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PHP;;D:\PHP;D:\MySQL\MySQL Server 4.1\bin' $s = '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PHP;;D:\PHP;D:\MySQL\MySQL Server 4.1\bin' $search = 'D:\PHP' ;'?:\PHP' $match = StringRegExp($s, $search) MsgBox(0,$s, $match)oÝ÷ Ûú®¢×k&Þjëh×6$s = '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PHP;;D:\PHP;D:\MySQL\MySQL Server 4.1\bin' $search = 'D:\PHP' ;'?:\PHP' If StringInStr($s, $search) Then MsgBox(0,$s, "Found- " & $search) Else MsgBox(0,$s, "Not Found- " & $search) EndIf EndFuncAutoIt is the shiznit. I love it.
hmsSurprise Posted April 20, 2007 Author Posted April 20, 2007 Maybe... $s = '%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PHP;;D:\PHP;D:\MySQL\MySQL Server 4.1\bin' $search = 'D:\PHP' ;'?:\PHP' If StringInStr($s, $search) Then MsgBox(0,$s, "Found- " & $search) Else MsgBox(0,$s, "Not Found- " & $search) EndIf Tried that with $search = '?:\PHP'. Since it wouldn't treat ? as a wildcard I started looking at regexp. One solution is to just find ':\PHP', then extract the substring starting one position b4 this and evaluate the first character of the substring. jh
Sokko Posted April 20, 2007 Posted April 20, 2007 (edited) Since it wouldn't treat ? as a wildcard I started looking at regexp. One solution is to just find ':\PHP', then extract the substring starting one position b4 this and evaluate the first character of the substring.A period in regex is equivalent to the old DOS wildcard "?". ".:\\PHP" would match any single character followed by ":\PHP". You may want to use "\w" instead, which will only match letters and the underscore, as in "\w:\\PHP". Also, look at the possible values for the "flag" parameter for StringRegExp in the help file, you can have it return the matched text in an array. Edited April 20, 2007 by Sokko
hmsSurprise Posted April 20, 2007 Author Posted April 20, 2007 A period in regex is equivalent to the old DOS wildcard "?". ".:\\PHP" would match any single character followed by ":\PHP". You may want to use "\w" instead, which will only match letters and the underscore, as in "\w:\\PHP". Also, look at the possible values for the "flag" parameter for StringRegExp in the help file, you can have it return the matched text in an array. Thanks again, you have been quite helpful. I will certainly save this for future use. I actually solved it another way. $found = StringInStr($s, ':\PHP') if $found Then $s = StringReplace ( $s, ($found -1), $dvDrive ) Else ;;Append to string. EndIf
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