Hi,
I'm wanting to Reverse find and replace a particular character in a
Powershell string. e.g. reverse find "b" in "abcabc" and replace with
"d" to give "abcadc". Could someone please advise how this could be
achieved ?
Thanks,
Patrick
|
|
0
|
|
|
|
Reply
|
Patrick
|
1/7/2010 10:23:06 PM |
|
Sorry - also should have stated that just the first instance of a
particular character should be replaced.
On Jan 8, 11:23=A0am, Patrick <prynh...@gmail.com> wrote:
> Hi,
>
> I'm wanting to Reverse find and replace a particular character in a
> Powershell string. =A0e.g. reverse find "b" in "abcabc" and replace with
> "d" to give "abcadc". =A0Could someone please advise how this could be
> achieved ?
>
> Thanks,
>
> Patrick
|
|
0
|
|
|
|
Reply
|
Patrick
|
1/7/2010 10:30:07 PM
|
|
VHJ5IHRoZXNlOg0KDQokcyA9ICdhYmNhYmNhYmNhYmMnDQokZmluZCA9ICdiJw0KJHJlcGxhY2Ug
PSAnXycNCg0KIyBsYXN0IGluc3RhbmNlDQokcyAtcmVwbGFjZSAiXiguKikoJGZpbmQpKC4qKSQi
LCAiYCQxJHJlcGxhY2VgJDMiDQoNCiMgZmlyc3QgaW5zdGFuY2UNCiRzIC1yZXBsYWNlICJeKFte
JGZpbmRdKikoJGZpbmQpKC4qKSQiLCAiYCQxJHJlcGxhY2VgJDMiDQoNCi0tIA0KUm9iZXJ0
|
|
0
|
|
|
|
Reply
|
Robert
|
1/7/2010 10:58:52 PM
|
|
Thanks Robert. I see that $1 and $3 are the regexp matches either side
of $find. I was able to get correct output for the values provided
below. However, the following example does not appear to work with
this code:
$s =3D '123123123123'
$find =3D '2'
$replace =3D '9'
$s -replace "^(.*)($find)(.*)$", "`$1$replace`$3"
$s -replace "^([^$find]*)($find)(.*)$", "`$1$replace`$3"
I incorrectly get "$193, and $193123123123" respectively. I presume
that "2" is a special case (i.e. $2)
Regards,
Patrick
On Jan 8, 11:58=A0am, "Robert Robelo" <Ki...@HighPlainsDrifter.com>
wrote:
> Try these:
>
> $s =3D 'abcabcabcabc'
> $find =3D 'b'
> $replace =3D '_'
>
> # last instance
> $s -replace "^(.*)($find)(.*)$", "`$1$replace`$3"
>
> # first instance
> $s -replace "^([^$find]*)($find)(.*)$", "`$1$replace`$3"
>
> --
> Robert
|
|
0
|
|
|
|
Reply
|
Patrick
|
1/7/2010 11:09:10 PM
|
|
Actually, any combination of a string involving digits seems to break:
$s =3D '789789789a9'
$find =3D 'a'
$replace =3D '9'
etc
On Jan 8, 12:09=A0pm, Patrick <prynh...@gmail.com> wrote:
> Thanks Robert. I see that $1 and $3 are the regexp matches either side
> of $find. =A0I was able to get correct output for the values provided
> below. =A0However, the following example does not appear to work with
> this code:
>
> $s =3D '123123123123'
> $find =3D '2'
> $replace =3D '9'
>
> $s -replace "^(.*)($find)(.*)$", "`$1$replace`$3"
> $s -replace "^([^$find]*)($find)(.*)$", "`$1$replace`$3"
>
> I incorrectly get "$193, and $193123123123" respectively. =A0I presume
> that "2" is a special case (i.e. $2)
>
> Regards,
>
> Patrick
>
> On Jan 8, 11:58=A0am, "Robert Robelo" <Ki...@HighPlainsDrifter.com>
> wrote:
>
> > Try these:
>
> > $s =3D 'abcabcabcabc'
> > $find =3D 'b'
> > $replace =3D '_'
>
> > # last instance
> > $s -replace "^(.*)($find)(.*)$", "`$1$replace`$3"
>
> > # first instance
> > $s -replace "^([^$find]*)($find)(.*)$", "`$1$replace`$3"
>
> > --
> > Robert
|
|
0
|
|
|
|
Reply
|
Patrick
|
1/7/2010 11:19:33 PM
|
|
I think you'll need to use a real regex for this:
$string = "abcabc"
$r = new-object System.Text.RegularExpressions.Regex
("b",[System.Text.RegularExpressions.RegexOptions]::RightToLeft)
$r.replace($string,"d",1)
"Patrick" wrote:
> Hi,
>
> I'm wanting to Reverse find and replace a particular character in a
> Powershell string. e.g. reverse find "b" in "abcabc" and replace with
> "d" to give "abcadc". Could someone please advise how this could be
> achieved ?
>
> Thanks,
>
> Patrick
> .
>
|
|
0
|
|
|
|
Reply
|
Utf
|
1/8/2010 3:33:01 AM
|
|
UmlnaHQsIHRvIGZpeCB0aGlzIEp1c3QgaXNvbGF0ZSB0aGUgdmFyaWFibGUgbmFtZXMgd2l0aCBi
cmFjZXM6DQoNCiRzMSA9ICdhYmNhYmNhYmNhYmMnDQokZmluZCA9ICdiJzsgJHJlcGxhY2UgPSAn
ZCcNCiRzMSAtcmVwbGFjZSAiXihbXiRmaW5kXSopKCRmaW5kKSguKikkIiwgImAkezF9JHtyZXBs
YWNlfWAkezN9Ig0KJHMxIC1yZXBsYWNlICJeKC4qKSgkZmluZCkoLiopJCIsICJgJHsxfSR7cmVw
bGFjZX1gJHszfSINCg0KJHMyID0gJzEyMzEyMzEyMzEyMycNCiRmaW5kID0gJzInOyAkcmVwbGFj
ZSA9ICc5Jw0KJHMyIC1yZXBsYWNlICJeKFteJGZpbmRdKikoJGZpbmQpKC4qKSQiLCAiYCR7MX0k
e3JlcGxhY2V9YCR7M30iDQokczIgLXJlcGxhY2UgIl4oLiopKCRmaW5kKSguKikkIiwgImAkezF9
JHtyZXBsYWNlfWAkezN9Ig0KDQokczMgPSAnNzg5YTc4OWE3ODlhOScNCiRmaW5kID0gJ2EnOyAk
cmVwbGFjZSA9ICc5Jw0KJHMzIC1yZXBsYWNlICJeKFteJGZpbmRdKikoJGZpbmQpKC4qKSQiLCAi
YCR7MX0ke3JlcGxhY2V9YCR7M30iDQokczMgLXJlcGxhY2UgIl4oLiopKCRmaW5kKSguKikkIiwg
ImAkezF9JHtyZXBsYWNlfWAkezN9Ig0KDQotLSANClJvYmVydA==
|
|
0
|
|
|
|
Reply
|
Robert
|
1/8/2010 3:55:34 AM
|
|
|
6 Replies
969 Views
(page loaded in 0.134 seconds)
Similiar Articles: Reverse Find and Replace ? - microsoft.public.windows.powershell ...Hi, I'm wanting to Reverse find and replace a particular character in a Powershell string. e.g. reverse find "b" in "abcabc" and replace with "d... find and replace - microsoft.public.windows.live.mail.desktop ...Hi, I'm wanting to Reverse find and replace a particular character in a Powershell string. e.g. reverse find "b" in "abcabc" and replace with "d... find in files and replace - microsoft.public.windows.powershell ...For my third example, I'd like to show a "reverse search and replace". In this type of search, you reverse the contents of the file and regular expression, perform ... Find and Replace any digit - microsoft.public.word.docmanagement ...I tried putting this in the Find and Replace but is not > working. In Find What ... Reverse Find and Replace ? - microsoft.public.windows.powershell ... Actually, any ... Resizing "Find and Replace" box - microsoft.public.word ...Resizing "Find and Replace" box - microsoft.public.word ... > > You can remove ... New Line in the default value of a text box in ... Reverse Find and Replace ... find and delete text box - microsoft.public.word.vba.general ...Resizing "Find and Replace" box - microsoft.public.word ... > > You can remove ... New Line in the default value of a text box in ... Reverse Find and Replace ... Apostrophe in search string - microsoft.public.access.formscoding ...When you try and replace one apostrophe by two, you get a reverse slanted ... using n in command mode, or N to reverse direction. When you want to search for a string ... Setvalue property to default value - microsoft.public.access ...Resizing "Find and Replace" box - microsoft.public.word ... > > You can remove ... New Line in the default value of a text box in ... Reverse Find and Replace ... Undo only by single character in Word 2007? - microsoft.public ...When you try and replace one apostrophe by two, you get a reverse slanted character ... ... Reverse Find and Replace ? - microsoft.public.windows.powershell ... ... Moving text around cells without moving boarder lines - microsoft ...Reverse Find and Replace ? - microsoft.public.windows.powershell ... Moving text around cells without moving boarder lines - microsoft ... Resizing "Find and Replace" box ... Reverse Find and Replace ? - microsoft.public.windows.powershell ...Hi, I'm wanting to Reverse find and replace a particular character in a Powershell string. e.g. reverse find "b" in "abcabc" and replace with "d... Reverse Find and Replace ? - Vista ForumsHi, I'm wanting to Reverse find and replace a particular character in a Powershell string. e.g. reverse find "b" in "abcabc" and replace with "d" to give "abcadc" Vim tips: The basics of search and replace | Linux.comAfter running a search once, you can repeat it by using n in command mode, or N to reverse direction. When you want to search for a string of text and replace it with ... Better Find and Replace on HTML Content - Full Service Web Agency ...For my third example, I'd like to show a "reverse search and replace". In this type of search, you reverse the contents of the file and regular expression, perform ... Find location and replace reverse light switch? 2005 Renault - FixYaFind location and replace reverse light switch? 2005 Renault Megane Dynamique Cabriolet 7/20/2012 5:26:23 PM
|