Jump to content

Need a correct pattern for stringregexReplace


Recommended Posts

#include <array.au3>
$l = "AutoIt_is_a_star"
   $xl = StringRegExpReplace($l, '.*(is|are).*', '$1.txt')
     
    ConsoleWrite($xl)


Exit

Hi, for the example above, how can i edit the pattern so it only print .txt  if there is not any found from the pattern...it just printed the whole line out $l if there is not any is/are found...

Edited by iahngy
Link to comment
Share on other sites

I believe the "If...Then...Else" method is the way to go.

#include <Misc.au3>

Local $l = "AutoIt_i_a_star"

;Local $xl = StringRegExp($l, '(is|are)') ? StringRegExpReplace($l, '.*(is|are).*', '$1.txt') : '.txt' ; For AutoIt Beta version (3.3.9.13)
;Or
Local $xl = _Iif(StringRegExp($l, '(is|are)'), StringRegExpReplace($l, '.*(is|are).*', '$1.txt'), '.txt') ; _Iif form Misc.au3 include file.
;Or use If...Then...Else...EndIf

ConsoleWrite($xl & @LF)
Link to comment
Share on other sites

Thank you Malkey.

How do i use the newer version of AutoIt into the current editor ...it doesnt compile with  the format ,

StringRegExp($l, '(is|are)') ? StringRegExpReplace($l, '.*(is|are).*', '$1.txt') : '.txt'
Edited by iahngy
Link to comment
Share on other sites

The latest beta version is http://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.9.15-beta-setup.exe

With "AutoIt Script Editor.(Customised version of SciTE with lots of additional coding tools for AutoIt)" installed, when "autoit-v3.3.9.15-beta-setup.exe" is installed a "Beta Run", a "Beta Compile", and a "Beta Help" is automatically added to the "Tools" menu of SciTE.

So running or compiling the latest release version installed or the latest beta version installed is done by picking the appropriate menu item under SciTE's Tools menu.

The conditional operators "... ? ... : ..." only works on the later beta versions and will not compile on the latest AutoIt release version 3.3.8.1.

Of course, if you want to see the results of the compiled script, you will need to replace the ConsoleWrite() with a MsgBox() function.

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