Jump to content

Recommended Posts

Posted

I was thinking about starting a small project, but when weighing up what would be needed, one of the requirements would be to find and replace all strings in an AutoIt script, and the more I thought about it, the more difficult and complex it seemed, and I'd have absolutely no chance of creating a regex pattern for something like that.

" 'strings like this for example' ", and worse "these one's".

I've had a quick unsuccessful search, does anyone know if one exists?

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

#Include <Array.au3>

$str = "MsgBox(64, 'Title', 'My ''test''')&, '''test'' My' &, 'M ''test'' y' ; $var = '"
$str &= @CRLF & 'MsgBox(64, "Title''s", ''test'') & ""'
$str &= @CRLF & '"these one''s"'
$str &= @CRLF & '" ''strings like this for example'' "'


$aOut = StringRegExp($str, '(''(?:[^''\r\n]*(?:'''')*[^''\r\n]*)*?''(?!'')|"(?:[^"\r\n]*(?:"")*[^"\r\n]*)*?"(?!"))', 3)
ConsoleWrite($str & @CRLF)
_ArrayDisplay($aOut)

Posted

Replace strings to what exactly?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 1/15/2014 at 1:12 PM, asdf8 said:
#Include <Array.au3>

$str = "MsgBox(64, 'Title', 'My ''test''')&, '''test'' My' &, 'M ''test'' y' ; $var = '"
$str &= @CRLF & 'MsgBox(64, "Title''s", ''test'') & ""'
$str &= @CRLF & '"these one''s"'
$str &= @CRLF & '" ''strings like this for example'' "'


$aOut = StringRegExp($str, '(''(?:[^''\r\n]*(?:'''')*[^''\r\n]*)*?''(?!'')|"(?:[^"\r\n]*(?:"")*[^"\r\n]*)*?"(?!"))', 3)
ConsoleWrite($str & @CRLF)
_ArrayDisplay($aOut)

That's quite great.

Thank you.

Shame it grabs strings from comments, but suppose they could be stripped first.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

Look at my Script Parsing thread for removing comments beforehand.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

The regexp part is tricky. When replacing multiple strings, it's essential to replace the longest strings first to avoid replacing part of a longer string by mistake. I don't know if there are many other functions to sort by length, but I wrote one if it's any use _ArraySortByLen(). Link

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
  • Recently Browsing   0 members

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