Jump to content

How to do search-replace with regexp in text buffer?


Recommended Posts

Hello!

Is it possible to do with AutoIt the next thing.

1. Copy in text buffer (CTRL+c) all text from this page:

My link

2. Do some search-replaces in text buffer (Clipget) with StringRexExpReplace()

3. Copy (CTRL+v) modified text buffer in MS Word or WordPad.

All the tables is crushing in a plain text.

Is it possible to do search-replaces with saving table structure?

Link to comment
Share on other sites

Looks to be like you want to copy data from some html tables into word tables. (I couldn't open the page to verify)

I'd advise against copy-pasting, but rather use the _IE functions to load the table data into an array, use StringRexExpReplace() on that and then write to a doc file using the _Word functions.

This approach should be more reliable and allow you to maintain the table structure.

Link to comment
Share on other sites

Looks to be like you want to copy data from some html tables into word tables. (I couldn't open the page to verify)

I'd advise against copy-pasting, but rather use the _IE functions to load the table data into an array, use StringRexExpReplace() on that and then write to a doc file using the _Word functions.

This approach should be more reliable and allow you to maintain the table structure.

Yes, these tables are being copied (CTRL+c) from IE(or Firefox) to MS Word (CTRL+v). Or we have to just modify some text in MS Word. (It is not illegal!). Pages consist not with tables only, but with some other text. And I have to do some replaces in text and tables.

I've tried to do replaces in MS Word, but its' search-replace function is too weak if we compare with PCRE.

Edited by Suppir
Link to comment
Share on other sites

 you should try a look at

_ClipBoard_GetDataEx()
and the example in the help 

AndyG, I really can not understand how this function works (my English is not very good).

For example:

we create some table with text in MS Word.

Then we put it in buffer (CTRL+c)

Then we should do replaces in buffer-data

Then paste modified test back to Word.

Link to comment
Share on other sites

If your link worked we could check to see what you are actually working with.

I would think that the better method would be to modify the Data BEFORE creating the Word document. I'm also assuming here that you are actually creating a *.doc file and not just foolishly using MSWord as an html editor.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

If your link worked we could check to see what you are actually working with.

I would think that the better method would be to modify the Data BEFORE creating the Word document. I'm also assuming here that you are actually creating a *.doc file and not just foolishly using MSWord as an html editor.

Can you try this page for example? http://www40.statcan.ca/l01/cst01/labr69a-eng.htm

This page contains some tables and text. I want to select all the page in buffer (CTRL+c); then do in buffer some replaces with regular expressions; then copy resulting text (with tables) in MS Word.

Link to comment
Share on other sites

You don't work on anything while it's still in the buffer. You read it out using ClipGet() and then work with that and if you want you can put it back into the buffer after.

Example

$sStr = ClipGet()
$sStr = StringRegExpReplace($sStr, "(?i)[aeiou]", "^")
ClipPut($sStr)

I'm sure that you can easily do it by using INetRead(), BinaryToString() and some of the functions in the Word.au3 UDF, or just as easily using InetGet() to get it to a file then FileRead() and again the functions in the Word.au3 UDF.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

then copy resulting text (with tables) in MS Word.

this is the problem....In the clipboard is only pure text, nothing else. Because the only data (that you "copy" from the website) is text. Only content, no rows or columns of the "tables".

I would prefer an other way. Read the html-code of the website, change/replace the text or something else and write this html-file to disk. Then import this file into MS-Word. I am an Open-Office-User and this works great! The formatting is preserved.

If you need to have a formatted table, try to paste the clipboard into an Excel-sheet. Then the data is inserted into the table "at the right way", like an import of CSV. Btw, this should work with an embedded Spreadsheet in a Word-document. With OO, it does.

Link to comment
Share on other sites

this is the problem....In the clipboard is only pure text, nothing else. Because the only data (that you "copy" from the website) is text. Only content, no rows or columns of the "tables".

Not quite Andy. You can go to any web page with text and tables, Ctrl+A to select all, Ctrl+C to copy. Open a new MSWord Document and Ctrl+V to paste it in. You will still have the tables although they may be arranged differently on the page because of page margins.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

 @GEOSoft, yes this is true^^, but this is why i mentioned _ClipBoard_GetDataEx(), not with  $CF_TEXT, but perhaps with one of the metafileformats. I know how to "paste" pictures/bitmaps from the clipboard with AutoIt, but i never tried to "import" a spreadsheet. I will try to write a script, could be useful....

/Edit/

You will still have the tables although they may be arranged differently on the page because of page margins.

So there is no reason to try an other way. Copy the website into word and edit the text wit the word.udf Edited by AndyG
Link to comment
Share on other sites

So there is no reason to try an other way. Copy the website into word and edit the text wit the word.udf

That may well work, I've been trying to suggest getting the source for the page, edit that and then put it into the Word document. Much easier when you have a file to work from instead of the clipboard. At least you have something that you can actually read to see what you are doing.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...