![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | -replace operator This is probably a regex question as opposed to powershell but I am confused by an example of the -replace operator on page 89 in the user guide: > "abc" -replace "\w*", "new" newnew Why does this match twice? It seems to me that if \w* is greedy, it should take them all. If it is not, it should grab "", "a", "ab", "abc". The > "abc" -replace "\w?", "new" example is similar. bob |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: -replace operator Bob, My interpretation is that the result is because of the * metacharacter/quantifier. It matches zero or more occurrences. I assume that the first time it matches three characters. So it can still match zero characters. So you get two replacement character sequences. On the other hand if you use + instead of * it matches three characters only once. So the output for + is "new" rather than "newnew". At least that's my $0.02. Andrew Watt MVP On Fri, 30 Jun 2006 14:32:46 -0400, "Bob Weiner" <bob@engr.uconn.edu> wrote: >This is probably a regex question as opposed to powershell but I am confused >by an example of the -replace operator on page 89 in the user guide: > >> "abc" -replace "\w*", "new" >newnew > >Why does this match twice? It seems to me that if \w* is greedy, it should >take them all. If it is not, it should grab "", "a", "ab", "abc". > >The >> "abc" -replace "\w?", "new" >example is similar. > >bob |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| -ne operator | PowerShell | |||
| -f operator | PowerShell | |||
| 64 bit binary or (-bor operator)? | PowerShell | |||
| What does the $() operator do? | PowerShell | |||
| Use of matching subexpressions in "-replace" operator | PowerShell | |||