Jump to content

Need some help with StringRegExpReplace


 Share

Recommended Posts

Hi all,

I need some help with StringRegExpReplace. I'm a bit of a noob with regular expressions. I want to replace all @CR characters in a string with @CRLF, but only if the carriage return isn't followed by a linefeed already.

Have been playing around with StringRegExpReplace, but can't get it to work. Any ideas?

Thanks

Edited by autoitter
Link to comment
Share on other sites

Hi all,

I need some help with StringRegExpReplace. I'm a bit of a noob with regular expressions. I want to replace all @CR characters in a string with @CRLF, but only if the carriage return isn't followed by a linefeed already.

Have been playing around with StringRegExpReplace, but can't get it to work. Any ideas?

Thanks

@toonboon I think what you meant was replace all @CRLF with @CR then replace all @CR with @CRLF.

@ autoitter, this might do what you want

;if text is $t then $r will be the converted text.
$r = StringRegExpReplace($t,"\r([^\n])","\r\n\1")
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

you could first replace all @CR@LF with @CRLF and then replace all other remaining @CRs with @CRLF.

@CR@LF is actually the same as @CRLF. My problem is that some @CR characters are followed by a @LF. I only want to replace "loose" @CR's.

I was trying something like this:

$strReceived = StringRegExpReplace($strReceived, "(\r)(^\n)", @CRLF & "\1")

But this doesn't work...

Link to comment
Share on other sites

autoitter, then my idea works for you :)

$strReceived = StringRegExpReplace($strReceived, "@CR@LF", @CRLF)
$strReceived = StringRegExpReplace($strReceived, "@CR", @CRLF)

that way all @CR's followed by a @LF (and thus @CR@LF) will be replaced by @CRLF (the same) then you can change all loose @CR's to @CRLF's.

[right]~What can I say, I'm a Simplistic person[/right]

Link to comment
Share on other sites

  • 9 years later...
stringreplace(StringReplace($text , @CR , @CRLF) , @LF & @LF , @LF)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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