Reverse Find and Replace ?

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
Patrick
1/7/2010 10:23:06 PM
windows.powershell 690 articles. 0 followers. Follow

6 Replies
2139 Views

Similar Articles

[PageSpeed] 59

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
Patrick
1/7/2010 10:30:07 PM
VHJ5IHRoZXNlOg0KDQokcyA9ICdhYmNhYmNhYmNhYmMnDQokZmluZCA9ICdiJw0KJHJlcGxhY2Ug
PSAnXycNCg0KIyBsYXN0IGluc3RhbmNlDQokcyAtcmVwbGFjZSAiXiguKikoJGZpbmQpKC4qKSQi
LCAiYCQxJHJlcGxhY2VgJDMiDQoNCiMgZmlyc3QgaW5zdGFuY2UNCiRzIC1yZXBsYWNlICJeKFte
JGZpbmRdKikoJGZpbmQpKC4qKSQiLCAiYCQxJHJlcGxhY2VgJDMiDQoNCi0tIA0KUm9iZXJ0

0
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
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
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
Utf
1/8/2010 3:33:01 AM
UmlnaHQsIHRvIGZpeCB0aGlzIEp1c3QgaXNvbGF0ZSB0aGUgdmFyaWFibGUgbmFtZXMgd2l0aCBi
cmFjZXM6DQoNCiRzMSA9ICdhYmNhYmNhYmNhYmMnDQokZmluZCA9ICdiJzsgJHJlcGxhY2UgPSAn
ZCcNCiRzMSAtcmVwbGFjZSAiXihbXiRmaW5kXSopKCRmaW5kKSguKikkIiwgImAkezF9JHtyZXBs
YWNlfWAkezN9Ig0KJHMxIC1yZXBsYWNlICJeKC4qKSgkZmluZCkoLiopJCIsICJgJHsxfSR7cmVw
bGFjZX1gJHszfSINCg0KJHMyID0gJzEyMzEyMzEyMzEyMycNCiRmaW5kID0gJzInOyAkcmVwbGFj
ZSA9ICc5Jw0KJHMyIC1yZXBsYWNlICJeKFteJGZpbmRdKikoJGZpbmQpKC4qKSQiLCAiYCR7MX0k
e3JlcGxhY2V9YCR7M30iDQokczIgLXJlcGxhY2UgIl4oLiopKCRmaW5kKSguKikkIiwgImAkezF9
JHtyZXBsYWNlfWAkezN9Ig0KDQokczMgPSAnNzg5YTc4OWE3ODlhOScNCiRmaW5kID0gJ2EnOyAk
cmVwbGFjZSA9ICc5Jw0KJHMzIC1yZXBsYWNlICJeKFteJGZpbmRdKikoJGZpbmQpKC4qKSQiLCAi
YCR7MX0ke3JlcGxhY2V9YCR7M30iDQokczMgLXJlcGxhY2UgIl4oLiopKCRmaW5kKSguKikkIiwg
ImAkezF9JHtyZXBsYWNlfWAkezN9Ig0KDQotLSANClJvYmVydA==

0
Robert
1/8/2010 3:55:34 AM
Reply:

Similar Artilces:

Dual boot in reverse
Hello, I have dual boot system: driveC --> WinXP driveD --->Vista Now, I do not need WinXP anymore. I want to have only Vista and combine C & D into one, single partition. How to do that without reinstalling Vista? Your thoughts appreciated, Claire On Sun, 17 Jan 2010 15:00:12 -0500, "Claire" <replyto@fra> wrote: >Hello, > I have dual boot system: >driveC --> WinXP >driveD --->Vista >Now, I do not need WinXP anymore. >I want to have only Vista and combine C & D into one, single partition. &...

how do I find the threequarter key
How do I type 1/4 and 3/4. I can type ½ by holding down Alt key and 171 on number pad. Alt+0190 will give you ¾ Note that for ¼ you use Alt+0180 and for ½ you use Alt+0189; Alt+171 gives you ◄ If you run a macro containing the following code, it will create a document that contains a table listing all of the symbols that can be created by using Alt+numeric keypad ' Macro created 12-08-98 by Doug Robbins to list symbols that can be inserted via Alt+keypad ' ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=3 ...

Finding Duplicated Text within Columns
I'd be grateful if anyone could help me with the following: I have 2 columns, both contain a number of items, some the same, some not; eg: Column A: Column B: Row 1: apple pear orange apple orange Row 2: orange banana banana orange Row 3: peach banana melon grape apple orange I need to compare the columns and find which rows are NOT exactly the same and, preferably, to identify the differences. For instance, in the above example, I would ignore Row 2 as the cells contain the same items (albeit in a different order), but I w...

How can I find bottom row of a spreadsheet
I have a spreadsheet that has rows added to it by different areas of the office. I need to set up a "front sheet" that will always show the last (bottom) row of "sheet1". I think there is a expression that will do this for me, but I do not know what it is or how to construct it. (I think it comes down the rows until it hits a blank then goes back up one row) Can anybody help with this please Bob It sounds like there won't be any blank rows. In that cases, you could use: =INDEX(Sheet2!A:A,COUNTA(Sheet2!A:A)) to pull in the last value in col. A of Sheet2. Then r...

The search is on to find an Australian Bank supporting OFX
For those Australians who maybe interested, I am conducting a search for any banks that will take up OFX support in the near future. So far the banks and instits. I have contacted are: Combank Westpac ANZ Esanda Citibank St George National Bank Suncorp Bank of Queensland Bendigo Bank Heritage Building Society IMB Encompass Credit Union Australian National Credit Union Discovery Queenslanders Credit Union I will let those interested know, by posting in this news group, any information that is helpful from this search. KJTV wrote: > For those Australians who maybe interested, I am con...

Finding incoming links to a workbook?
Is there a way to determine which workbooks are linking into another workbook? For example, I have a workbook sourcedata.xls on a network folder. Is there a way to find out which workbooks are linked to it? Not really. You could look through every excel file that you can see--but that won't help for the files you can't see -- the files on different pc's (local harddrives, thumbdrives, different network drives). If you want a less than optimal suggestion... Move or rename your file. Wait for the complaints to come in. Excel Nut wrote: > > Is there a way to determine ...

finding addresses
I have tried for several hours and failed. I want, say, A1 to contain 1. I want A2 to self generate its value as the cell above +1 etc. etc. but of course NOT using A1+1 because... ...if I delete one of the numbers in the sequence, I want that cell to become blank and all the remaining cells below to regenerate their numbers to remain sequential regardless of the blank or several blanks. One further limit is that if the renumbering hits a red cell (or several) then it misses them and continues below. I have tried Address(), row(), column() etc in various combinations to no avail. I would ...

How to find out OS edition from command line?
Hi folks, do you know how to find out OS edition from OS line? "Gene." <Gene@discussions.microsoft.com> wrote in message news:94C9D953-5395-4E42-A92D-3F81AC34034D@microsoft.com... > Hi folks, do you know how to find out OS edition from OS line? Winver Jim On Thu, 29 Apr 2010 15:09:01 -0700, Gene. <Gene@discussions.microsoft.com> wrote: >Hi folks, do you know how to find out OS edition from OS line? ver -- ---------------- Stubbo of Oz ---------------- On Fri, 30 Apr 2010 09:48:08 +1000, Stubbo of Oz <stubbo@invalid.invalid>...

REVERSING TEXT
HOW CAN I REVERSE TEXT AND PICTURES ON PUBLISHER TO PRINT ONTO T.SHIRTS spike <spike@discussions.microsoft.com> was very recently heard to utter: > HOW CAN I REVERSE TEXT AND PICTURES ON PUBLISHER TO PRINT ONTO > T.SHIRTS YES. PLEASE READ REPLY TO YOUR FIRST POST. Please do not talk in all caps. It is considered shouting and makes your post difficult to read and is rude. Your first message ("how do i reversie pictures and text for printing to t.shirts") is directly below this one and has been answered by yours truly. -- Ed Bennett - MVP Microsoft Publisher ...

OWA Find Names
When using OWA, you look up recipients for an e-mail using the "Find Names" window. It appears that the maximum number of results that will be returned is set at 100, with no customization obviously apparent from the OWA interface. I completely understand why you wouldn't want this number to get too high, especially in a large organization, but I have a need to increase it to at least 200, if not 250. Is there registry key where this can be controlled? Perhaps a way to set something in the IIS metabase? Any help is greatly appreciated. On Mon, 6 Feb 2006 13:34:17 -080...

Possible to reverse a row of entries?
Is there a command or format command that will let me take a row of entries and reverse them? In other words if I have rows #1 through #10 top to bottom, I now want them to go #10 to #1 top to bottom. thanks Rick Hi in B1 enter =OFFET($A$10,-(ROW()-1),0) and copy down for ten rows -- Regards Frank Kabel Frankfurt, Germany rs wrote: > Is there a command or format command that will let me take a row of > entries and reverse them? In other words if I have rows #1 through > #10 top to bottom, I now want them to go #10 to #1 top to bottom. > > thanks > > Rick Ric...

cannot find pst file?
I cannot find my pst file so I can make a backup copy of it. If I look in "properties for personal folders", then click on "advanced", I can see the data should be stored at C:\Documents and Settings\Steve\Local Settings\Application Data\Microsoft\Outlook\outlook.pst. But if I do a search on drive c: I cannot find a file with that name there. What do you suggest I try? It's a hidden file on Win 2K and higher. -- Russ Valentine [MVP-Outlook] "Steve M. Sylvest" <ssylvest@charter.net> wrote in message news:01ac01c36507$ff810d90$a501280a@phx.gbl....

Reverse arrow for hyperlinks
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel I need to find a 'reversing arrow' that I can add to the toolbar to click on after using a hyperlink. <br> You can do this in Windows but I cannot find a similar facility when using my macbook. <br> I use longish word docs that often have links to other parts of the document. How do I get back to the point at which I activated the hyperlink, apart from scrolling back laboriously? <br> Thanks for any solutions. Shift + F5, provided you have not closed the document. Shift + F5 tak...

Reverse engineering
I have to document an Access 97 that has grown like wild blackberries. The database's creator has left us no documentation at all and I would like Visio to extract as much information as possible. So far I have extracted a good UML of the tables. Currently I am doing screen dumps of the forms to show what the screens look like - then pasting them into Visio. What else can I do? Can I extract the queries, forms, reports, macros and modules also - and save and print these out from Visio? Please advise. As I remember there was a "database documenter" with Access. I don...

Find attachments
I have hundreds of client folders, how can I find all attachments without going through every In and Out folder? "PeterL" <peterl@national.com> wrote in message news:uyBwgY7qHHA.4764@TK2MSFTNGP06.phx.gbl... >I have hundreds of client folders, how can I find all attachments without >going through every In and Out folder? What version of Outlook? If it's 2003 or 2007, just set up a search folder. -- f.h. "F.H. Muffman" <f.h.muffman@hotmail.com> wrote in message news:OG2ZLC8qHHA.1212@TK2MSFTNGP05.phx.gbl... > "PeterL" <pete...

Formulas reversed
Using Office 2007 and windows XP. The back slash has become "multiply" and the star has become "divide". In other words, these two symbols are reversed. Have no idea how this happened. How can it be reversed back to normal? thanks. Please give an example of formula, values of input cells and result of formula -- Kind regards, Niek Otten Microsoft MVP - Excel "RENEE" <RENEE@discussions.microsoft.com> wrote in message news:C56D666E-70CD-4E8F-97F9-1FAD9CE92024@microsoft.com... > Using Office 2007 and windows XP. The back slas...

Find a Message
Not sure if this is right group for this or what. When I use the "Find a Message" function in OE 6.0, most of the itme it eats up all the computer processing functions and have to reboot it afterwards. My PC runs very, very slow after a search of all my emails for body text. I use OE 6.0 with FireFox and XP Serv P3. tks all bw Backup your message store and then go to File | Folder | Compact all. = That will shrink the size of the folders and reduce wasted space and = performance should improve. If it doesn't go to File | Identities and = set up a new I...

How to find a particular word?
Hello, everybody! I have a dictionary that I created in excel and that is becoming too large to find particular words. I have one problem with finding. I want to find, for example, 'vision,' but it finds all words containing 'vision,' i.e. division, divisional, visionary, provision, etc. What I need is that I want to find only the word 'vision' in order not to waste time, finding unrelated words, as mentioned above. Is there any solution to it? Please help me. Thanks in advance. Jack Hit Ctrl+F.From Find window click on 'Options'. Make s...

Can I reverse the order of data in a set of cells?
I have a column of cells filed with data. I know I can transpose the data 90 degrees, but is there a way to cut or copy the data in the cells and paste it so the values are in the opposite order, i.e. a 180 degree difference? Thanks to anyone who can help. I am using Excel 2003. One way, insert a new column or use an existing, number it from 1 - n (where n is the last index value you want to reverse the order of, so if your column is 100 rows number the help column 1, 2, 3 - 100) select both columns and sort descending on the help column -- Regards, Peo Sjoblom "salwitt"...

Can't find "favorites" in the Navigation Pane
Whew, Outlook 2007... I wish I could go back to Outlook 2000! I have now "lost' the "Favorites Folder" in the Navigation Panel. It is not in the "View"... "Navigation Panel" folder. How do I get it back? Thanks. -- -always learning!- Apologies... if I searched further down I would have found the answer to my question: Ctrl+1 -- -always learning!- "billibo" wrote: > Whew, Outlook 2007... I wish I could go back to Outlook 2000! I have now > "lost' the "Favorites Folder" in the Navigation Panel. > > It i...

Finding Cell with Minor loss of fidelity
I have a Excel Spreadsheet that was created in Excel 2003, but updated with Excel 2007. Whenever I save it, it runs the Compatibility Checker, and comes back with a 'Minor loss of fidelity' message. I would like to find the cell(s) that thie issue talking about. Is there a way to find which cell(s) have the issue, so I can fix them? -- Doug Krohn Hi, when saving the spreadsheet Save it as xlsm "Doug Krohn" wrote: > I have a Excel Spreadsheet that was created in Excel 2003, but updated with > Excel 2007. > Whenever I save it, it runs the Compati...

Reversal encryption
Hello, I need a good algorithm for encrypting some vital information about my app in an INI file. I have a class for MD5, but it's not reversible. I'd like to use a private or public key to decrypt the text. By the way, what's the difference between private and public key when we talk about encryption? Sugestions, please? I have googled about the public key encryption and found that CryptoAPI is used frequently. Is this API part of the Windows? If not, what I need to use it? "Jeova Almeida" <jeovaalmeida@yahoo.com> escreveu na mensagem news:e1uwDhuTJHA...

Reverse List?
Greetings! What's happening with the reverse list as of late? It seems like it's not updating anymore since the contacts that I add are never displayed. I have tested this by using my primary account to add my secondary account and then accepting the invitation on the secondary account, my secondary account (target) could see my primary account (source) in the list, but my primary account could not see my secondary account, and both had each other in their contact lists. Thanks in advance; -- jps Greetings jps, I have no real fix for you, but I can confirm...

Cannot find network neigberhood for XP?
I am using XP with SP3, and cannot find my netowork neigberhood, which disappear on my desktop, does anyone have any suggestions on how to locate it? Thanks in advance for any suggestions Eric "Eric" <Eric@discussions.microsoft.com> wrote in message news:0BDA67E4-7E39-42C2-B8C5-0220D1146A98@microsoft.com... >I am using XP with SP3, and cannot find my netowork neigberhood, which > disappear on my desktop, does anyone have any suggestions on how to locate > it? > Thanks in advance for any suggestions > Eric Right-click on your desktop, pick Prope...

Customer EFT Reversal
In GP 10, we're getting ready to start using Electronic Funds Transfer in our Receivables area, i.e, we're going to take our customers' payments directly from their bank accounts. If there's a problem where we take a customer's money in error, how do we put it back into their back account using EFT? Thanks! Mary Fetsch ...