Jump to content

Replacing Xml Text Using Stringregexp


Recommended Posts

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'.

Link to comment
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.

Link to comment
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 \.

Link to comment
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.

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.

Link to comment
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

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...