Jump to content

Help with regular expressions


Surya
 Share

Recommended Posts

I have no idea what regular expressions are:

I need to convert this line to AutoIt function Stringregexpreplace()

echo <some random characters>| perl -pe 's/\x0D\x0A/\x0A/g'

where 's/\x0D\x0A/\x0A/g' is the regular expression I need to convert to Autoit Understandable.

No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Link to comment
Share on other sites

7 hours ago, Danp2 said:

I believe that is just replacing the combination of CR/LF with a LF.

Yes, it is !

Local $sString
$sString = "1Hello " & @LF & " 2brave" & @CRLF & @CRLF & @LF & " 3new" & @CRLF & " 4world"
$sString = StringRegExpReplace($sString, "(?>\r\n)", @LF)
FileWrite(@ScriptDir & "\Replacetest.txt", $sString)

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

10 hours ago, Surya said:

I need to convert this line to AutoIt function Stringregexpreplace(). [...] where 's/\x0D\x0A/\x0A/g' is the regular expression I need to convert to Autoit understandable.

My RegEx above replaces CRLF with LF :

Before :

Before.png.02dfe69732aa4decc764429fa18cfa6d.png

After :

After.png.6f4954c52bddaa7198d8bcb2f78714d1.png

1 hour ago, Surya said:

Don't know why but when I save the output to a png file it doesn't seem to open

I haven't pipe or redirect the output to a png file. BTW : I can't open your graphics either -> decoding error.

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

This function will open the supplied  png image file.  However, a lot of the image is transparent which suggests there is more to be done than just changing all 0D0A's to 0A.

_Png0D0ATo0A("scrnshot.png", "scrnshotModified.png")
ShellExecute("scrnshotModified.png")

_Png0D0ATo0A("scrnshot2.png", "scrnshot2Modified.png")
ShellExecute("scrnshot2Modified.png")


Func _Png0D0ATo0A($sFileNameIn, $sFileNameOut)
    ;------------------- Read from in file --------------------
    Local $hFileOpen = FileOpen($sFileNameIn, 16) ; $FO_BINARY (16) = Force binary mode
    $b = FileRead($hFileOpen)
    ;ConsoleWrite($b & @CRLF)
    $a = StringRegExpReplace($b, "(0D0A)", "0A")
    FileClose($hFileOpen)

    ;------------------- Write to out file --------------------
    Local $hFileOpenNew = FileOpen($sFileNameOut, 18) ; $FO_BINARY (16) = Force binary mode PLUS $FO_OVERWRITE (2) = Write mode (erase previous contents)
    FileWrite($hFileOpenNew, $a)
    ;ConsoleWrite($a & @CRLF)
    FileClose($hFileOpenNew)
EndFunc   ;==>_Png0D0ATo0A

 

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