![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Changing guids to uppercase I have a file (XML file) that has GUIDs sprinkled througout it. I would like to convert all the GUIDs to upper-case. I would have thought that this would work but I can't quite figure it out. (get-content filename) -replace "[0-9a-fA-F-]{36}", ([string]'$0').toupper() The regex expression is matching correctly but the $0.toupper() simply isn't working. What am I missing? Any hints appreciated... |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Changing guids to uppercase "p2" <p2@discussions.microsoft.com> wrote in message news F01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...>I have a file (XML file) that has GUIDs sprinkled througout it. I would >like > to convert all the GUIDs to upper-case. I would have thought that this > would > work but I can't quite figure it out. > > (get-content filename) -replace "[0-9a-fA-F-]{36}", > ([string]'$0').toupper() > > The regex expression is matching correctly but the $0.toupper() simply > isn't > working. What am I missing? > > Any hints appreciated... Well I can tell you why it is not working but I haven't come up with an easy solution to the problem. The reason it doesn't work is that the $1 (should be 1 instead of 0) is only evaluated by the regex engine. So $1 isn't meaningful to PowerShell (most like is null) so calling ToUpper only results in an empty replacement string. Now if -replace supported a scriptblock that would be called for match evaluation (which is supported by .NET) then something like this would be easy: # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0 $hexCh = "[a-fA-F0-9]" $guidPattern = [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})" (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()} Now that would be wicked cool if this support were added. I think I will file this as an enhancement request on the connect site alongside my request for -matchall. Maybe somebody who is a bit more regex savy can come up with a regex way to capitalize with the .NET regex engine but since the examples for the MatchEvaluator delegates were demonstrating capitalization, I kind of doubt it. If you knew there was ever only one GUID per line then it would probably be easy to use -match to grab the GUID via the $matches variable and then capitalize that guid. Then turn around and use replace on the same line to replace the guid with the capitalized version. -- Keith |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Changing guids to uppercase "Keith Hill" <r_keith_hill@mailhot.nospamIdotcom> wrote in message news:O5bG6u3aHHA.348@TK2MSFTNGP02.phx.gbl... > "p2" <p2@discussions.microsoft.com> wrote in message > news F01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...> in an empty replacement string. Now if -replace supported a scriptblock > that would be called for match evaluation (which is supported by .NET) > then something like this would be easy: > > # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0 > $hexCh = "[a-fA-F0-9]" > $guidPattern = > [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})" > (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()} > > Now that would be wicked cool if this support were added. If anyone else likes this idea you can vote on it here: https://connect.microsoft.com/feedba...4447&SiteID=99 -- Keith |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Changing guids to uppercase There is a blog entry from Bruce Payette: http://blogs.msdn.com/powershell/arc...25/678259.aspx I think once powershell supports an easier way to work with delegates, the standard MatchEvaluator solution will do. The advantage is that it leverages existing .net paradigm so it is well known. Adding an ability to specify MatchEvaluator in the -replace operator may be nice too. //Andrew Keith Hill wrote: > "p2" <p2@discussions.microsoft.com> wrote in message > news F01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...>> I have a file (XML file) that has GUIDs sprinkled througout it. I >> would like >> to convert all the GUIDs to upper-case. I would have thought that this >> would >> work but I can't quite figure it out. >> >> (get-content filename) -replace "[0-9a-fA-F-]{36}", >> ([string]'$0').toupper() >> >> The regex expression is matching correctly but the $0.toupper() simply >> isn't >> working. What am I missing? >> >> Any hints appreciated... > > Well I can tell you why it is not working but I haven't come up with an > easy solution to the problem. The reason it doesn't work is that the $1 > (should be 1 instead of 0) is only evaluated by the regex engine. So $1 > isn't meaningful to PowerShell (most like is null) so calling ToUpper > only results in an empty replacement string. Now if -replace supported > a scriptblock that would be called for match evaluation (which is > supported by .NET) then something like this would be easy: > > # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0 > $hexCh = "[a-fA-F0-9]" > $guidPattern = > [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})" > (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()} > > Now that would be wicked cool if this support were added. I think I > will file this as an enhancement request on the connect site alongside > my request for -matchall. > > Maybe somebody who is a bit more regex savy can come up with a regex way > to capitalize with the .NET regex engine but since the examples for the > MatchEvaluator delegates were demonstrating capitalization, I kind of > doubt it. If you knew there was ever only one GUID per line then it > would probably be easy to use -match to grab the GUID via the $matches > variable and then capitalize that guid. Then turn around and use > replace on the same line to replace the guid with the capitalized version. > > -- > Keith |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Changing guids to uppercase did go the same way (matchevaluator and post by Bruce, as you can use the delegate directly. it will work now, as you do not need the match (ok not so usefull but as example) but to catch that you need to change the delegate as show in the post by Bruce. PoSH> [regex]::Replace("foo",".*",{get-date}.invoke()) 03/21/2007 11:29:1703/21/2007 11:29:17 Greetings /\/\o\/\/ "Andrew Savinykh" wrote: > There is a blog entry from Bruce Payette: > http://blogs.msdn.com/powershell/arc...25/678259.aspx > > I think once powershell supports an easier way to work with delegates, > the standard MatchEvaluator solution will do. The advantage is that it > leverages existing .net paradigm so it is well known. Adding an ability > to specify MatchEvaluator in the -replace operator may be nice too. > > //Andrew > > Keith Hill wrote: > > "p2" <p2@discussions.microsoft.com> wrote in message > > news F01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...> >> I have a file (XML file) that has GUIDs sprinkled througout it. I > >> would like > >> to convert all the GUIDs to upper-case. I would have thought that this > >> would > >> work but I can't quite figure it out. > >> > >> (get-content filename) -replace "[0-9a-fA-F-]{36}", > >> ([string]'$0').toupper() > >> > >> The regex expression is matching correctly but the $0.toupper() simply > >> isn't > >> working. What am I missing? > >> > >> Any hints appreciated... > > > > Well I can tell you why it is not working but I haven't come up with an > > easy solution to the problem. The reason it doesn't work is that the $1 > > (should be 1 instead of 0) is only evaluated by the regex engine. So $1 > > isn't meaningful to PowerShell (most like is null) so calling ToUpper > > only results in an empty replacement string. Now if -replace supported > > a scriptblock that would be called for match evaluation (which is > > supported by .NET) then something like this would be easy: > > > > # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0 > > $hexCh = "[a-fA-F0-9]" > > $guidPattern = > > [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})" > > (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()} > > > > Now that would be wicked cool if this support were added. I think I > > will file this as an enhancement request on the connect site alongside > > my request for -matchall. > > > > Maybe somebody who is a bit more regex savy can come up with a regex way > > to capitalize with the .NET regex engine but since the examples for the > > MatchEvaluator delegates were demonstrating capitalization, I kind of > > doubt it. If you knew there was ever only one GUID per line then it > > would probably be easy to use -match to grab the GUID via the $matches > > variable and then capitalize that guid. Then turn around and use > > replace on the same line to replace the guid with the capitalized version. > > > > -- > > Keith > |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: Changing guids to uppercase forget example plz ;-) as trhis is same as (get-date) "/\/\o\/\/ [MVP]" wrote: > did go the same way (matchevaluator and post by Bruce, as you can use the > delegate directly. > > it will work now, as you do not need the match (ok not so usefull but as > example) > but to catch that you need to change the delegate as show in the post by > Bruce. > > PoSH> [regex]::Replace("foo",".*",{get-date}.invoke()) > 03/21/2007 11:29:1703/21/2007 11:29:17 > > Greetings /\/\o\/\/ > > "Andrew Savinykh" wrote: > > > There is a blog entry from Bruce Payette: > > http://blogs.msdn.com/powershell/arc...25/678259.aspx > > > > I think once powershell supports an easier way to work with delegates, > > the standard MatchEvaluator solution will do. The advantage is that it > > leverages existing .net paradigm so it is well known. Adding an ability > > to specify MatchEvaluator in the -replace operator may be nice too. > > > > //Andrew > > > > Keith Hill wrote: > > > "p2" <p2@discussions.microsoft.com> wrote in message > > > news F01B5A9-9EAD-44A4-A481-8A07E725F3E6@microsoft.com...> > >> I have a file (XML file) that has GUIDs sprinkled througout it. I > > >> would like > > >> to convert all the GUIDs to upper-case. I would have thought that this > > >> would > > >> work but I can't quite figure it out. > > >> > > >> (get-content filename) -replace "[0-9a-fA-F-]{36}", > > >> ([string]'$0').toupper() > > >> > > >> The regex expression is matching correctly but the $0.toupper() simply > > >> isn't > > >> working. What am I missing? > > >> > > >> Any hints appreciated... > > > > > > Well I can tell you why it is not working but I haven't come up with an > > > easy solution to the problem. The reason it doesn't work is that the $1 > > > (should be 1 instead of 0) is only evaluated by the regex engine. So $1 > > > isn't meaningful to PowerShell (most like is null) so calling ToUpper > > > only results in an empty replacement string. Now if -replace supported > > > a scriptblock that would be called for match evaluation (which is > > > supported by .NET) then something like this would be easy: > > > > > > # !!!!! THIS DOES NOT WORK IN POWERSHELL 1.0 > > > $hexCh = "[a-fA-F0-9]" > > > $guidPattern = > > > [regex]"(?<guid>$hexCh{8}-$hexCh{4}-$hexCh{4}-$hexCh{4}-$hexCh{12})" > > > (get-content filename) -replace "$guidPattern", {$match.guid.ToUpper()} > > > > > > Now that would be wicked cool if this support were added. I think I > > > will file this as an enhancement request on the connect site alongside > > > my request for -matchall. > > > > > > Maybe somebody who is a bit more regex savy can come up with a regex way > > > to capitalize with the .NET regex engine but since the examples for the > > > MatchEvaluator delegates were demonstrating capitalization, I kind of > > > doubt it. If you knew there was ever only one GUID per line then it > > > would probably be easy to use -match to grab the GUID via the $matches > > > variable and then capitalize that guid. Then turn around and use > > > replace on the same line to replace the guid with the capitalized version. > > > > > > -- > > > Keith > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Typewriting lowercase after uppercase letters quickly | Erhard Glueck | Vista performance & maintenance | 7 | 01-10-2008 01:50 AM |
| media changing delays when changing tracks | cozzie2 | Vista music pictures video | 21 | 05-16-2007 09:34 PM |
| Changing the way of changing the colorscheme | Tipsko | Vista General | 1 | 02-27-2007 05:35 AM |
| Duplicate GUIDS... | Ross | Vista installation & setup | 0 | 01-22-2007 04:04 PM |
| Duplicate GUIDs... | Ross | Vista installation & setup | 0 | 01-22-2007 04:03 PM |