Sign in to follow this  
Followers 0
oholdeno

Replacing Xml Text Using Stringregexp

9 posts in this topic

If I need to replace the following exact text:

<Image PostProcess="keep">\S*</Image>

with say, a blank space

how would I do it?

What I put between the tags is supposed to mean '0 or more non-whitespace characters' in regular expression language.

I'm having trouble with the quotation marks around the word 'keep'.

Share this post


Link to post
Share on other sites



http://www.autoitscript.com/forum/index.php?showtopic=23627

It's also in the current release beta help file.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

http://www.autoitscript.com/forum/index.php?showtopic=23627

It's also in the current release beta help file.

i need to update my beta again. blah. that's cool that it made it to the help file.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

it doesn't say much about escaping special characters

also can someone clear up what the '?' does after a repeating pattern?

Share this post


Link to post
Share on other sites

? after a repeating pattern will find the smallest match instead of the largest. This is in the help file (though the help file sucks for most everthing else to do with regex).

Search the web for regular expressions and you will find alot. 90% is the same whatever library you are using.


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

If I need to replace the following exact text:

<Image PostProcess="keep">\S*</Image>

with say, a blank space

how would I do it?

What I put between the tags is supposed to mean '0 or more non-whitespace characters' in regular expression language.

I'm having trouble with the quotation marks around the word 'keep'.

Though not entirely familiar with AutoIT regex, in others if you are using regex to match or replace you need to escape special characters that would mean \" in the match side for quotes and \\S\* for the middle. If you are telling regex to match \ and * both are special characters and need to be escaped using a \.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Do you want to get rid of the entire string "<Image PostProcess="keep">\S*</Image>", or just the Image info "\S*" ?

A pattern of "<Image PostProcess="keep">(.*)</Image>" will eliminate the \S* text.

A pattern of "(<Image PostProcess=".*">.*</Image>)" will eliminate the complete string, regardless of the the "keep" or "\S*"

Really need more info on what you are doing and why.

Edited by Stumpii

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

Do you want to get rid of the entire string "<Image PostProcess="keep">\S*</Image>", or just the Image info "\S*" ?

A pattern of "<Image PostProcess="keep">(.*)</Image>" will eliminate the \S* text.

A pattern of "(<Image PostProcess=".*">.*</Image>)" will eliminate the complete string, regardless of the the "keep" or "\S*"

Really need more info on what you are doing and why.

Keep in mind that if you have two or more instances of this tag, your second example, Stumpii, will eliminate ALL text between the first and last instance.

<Image PostProcess="keep">\S*</Image>
....
....more XML
....
<Image PostProcess="keep">\S*</Image>

When you replace PostProcess="keep" with PostProcess=".*" , it will match ANY character up to the next double-quote. You need to add a "?", like so: PostProcess=".*?"


[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
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
Sign in to follow this  
Followers 0