forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Replace string in file with regular expressions [Resolved]

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Fri Nov 25, 2005 4:31 pm    Post subject: Replace string in file with regular expressions [Resolved] Reply with quote

Hi everybody,

I've been struggling all night trying to change this:

Code:
      <title>Motor Racing</title>
      <desc>V8 Supercars. Round 13. From Phillip Island.</desc>

To this:

Code:
      <title>V8 Supercars</title>
      <desc>Round 13. From Phillip Island.</desc>

Ok, that part's easy IF I know what the <desc></desc> field contains.

The bit I'm having trouble with is:
a.) The contents of <desc></desc> are unknown
b.) There are multiple <title>Motor Racing</title> entries, each with different <desc></desc> fields.
c.) I want to replace each <title>Motor Racing</title> entry in the file with it's respective <desc></desc> field (up to the first . or , etc).


This regular expression:

Code:
<title>Motor Racing</title>\s*<desc>.*\.

Should return this:

Code:
      <title>V8 Supercars</title>
      <desc>Round 13.

But it's not working. Crying or Very sad


With the following I get null for %z and %d

Code:

OPTION FIELDSEP, ">"
    %%SrchPattern = <title>Motor Racing</title>\s*<desc>.*\.
    %z = @string(RegxFind,%%File,%%SrchPattern,,)
    info string is %z
    parse "%a;%b;%c;%d",%z
    info desc is %d
 


Also, can you use multiple FIELDSEP separator characters? Like this:

Code:

OPTION FIELDSEP, "|,<,>"

or

OPTION FIELDSEP, "|","<",">"
 

_________________
cheers

Dave


Last edited by DaveR on Sat Nov 26, 2005 4:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Fri Nov 25, 2005 5:59 pm    Post subject: Reply with quote

From the string.dll help file it seems that this should do what I need:

Code:

%%ChgTitle = Motor Racing
%z = @string(RegxRepInFile,%%File,%%File2,"<title>%%ChgTitle</title>\s*<desc>(.*)\.","<title>$1</title>\s*<desc>",)

But I can not get it working. I've tried many variations without success.

_________________
cheers

Dave
Back to top
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Fri Nov 25, 2005 11:09 pm    Post subject: Reply with quote

Regular expressions are wonderful but sometimes a bit hard to work with. A careful study is advisable.

Try something like this:

Code:
%%in = "<title>Motor Racing</title>"@cr()"<desc>V8 Supercars. Round 13. From Phillip Island.</desc>"

%%out =  @string(regxreplace, %%in, "<title>[^<]*?</title>.\w*<desc>([^.]+)\. ([^<]*)</desc>", <title>$1</title><desc>$2</desc>,)


Greetz
Dread

PS: How 'bout that FileOps error?

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Sat Nov 26, 2005 3:48 am    Post subject: Reply with quote

Dr. Dread wrote:
Regular expressions are wonderful but sometimes a bit hard to work with. A careful study is advisable.

Hard is an understatement. Though I'm finding parts of string.dll's help file is not easy to understand either. Embarassed

You're example works great, if the search string is on one line. Does string.dll only work on one line at a time?

Quote:
PS: How 'bout that FileOps error?

Did you get 2nd email?

The error still occurs with any string.dll version later than 4.4 - which is going to be problem for me as RegxRepInFile was only added in a later version. The debug version you sent me did not provide any extra messages (still only got the std run time error message).

_________________
cheers

Dave
Back to top
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Sat Nov 26, 2005 9:14 am    Post subject: Reply with quote

DaveŽ wrote:
Hard is an understatement. Though I'm finding parts of string.dll's help file is not easy to understand either. Embarassed


There's also a link in the help file to a site with additional info and examples. RegEx's really aren't easy,
but if you master the basics you can do just about anything with strings.

DaveŽ wrote:
You're example works great, if the search string is on one line. Does string.dll only work on one line at a time?


Yes and no. Normal functions will work with the variables that you feed it. Regardless of multiple lines or not.
But FileOps is linebased as the DLL will cycle through each line of the (this is documented in the help file...) So
if your files aren't gigantic you could put them into a variable (string.dll has a function for that, too).

DaveŽ wrote:
Did you get 2nd email?


Nope, didn't get any 2nd mail Crying or Very sad

DaveŽ wrote:
The error still occurs with any string.dll version later than 4.4 - which is going to be problem for me as RegxRepInFile was only added in a later version. The debug version you sent me did not provide any extra messages (still only got the std run time error message).


Hmmmm. I will try something else. Watch your mail.

Greetz
Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Sat Nov 26, 2005 10:47 am    Post subject: Reply with quote

Dr. Dread wrote:
There's also a link in the help file to a site with additional info and examples. RegEx's really aren't easy,
but if you master the basics you can do just about anything with strings.

Yep, I've been reading that site for the last 6 or so hours (giving myself a headache!) trying to work out why I can't strip carriage returns and line feeds from a xml file. Stupid

Dr. Dread wrote:
But FileOps is linebased as the DLL will cycle through each line of the (this is documented in the help file...)

Ahh, yes. Right at the top of the FileOps page. Embarassed

Dr. Dread wrote:
So if your files aren't gigantic you could put them into a variable (string.dll has a function for that, too).

I'll give that a try. Assuming I can get that working I won't need to strip the CRLFs.

Dr. Dread wrote:
DaveŽ wrote:
Did you get 2nd email?

Nope, didn't get any 2nd mail Crying or Very sad

I've resent it to "support" and your regular email address.

Dr. Dread wrote:
Hmmmm. I will try something else. Watch your mail.

Got it. Test result has been sent to both email addresses.

_________________
cheers

Dave
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group