autoitter Posted November 23, 2008 Share Posted November 23, 2008 (edited) 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 November 23, 2008 by autoitter Link to comment Share on other sites More sharing options...
toonboon Posted November 23, 2008 Share Posted November 23, 2008 you could first replace all @CR@LF with @CRLF and then replace all other remaining @CRs with @CRLF. [right]~What can I say, I'm a Simplistic person[/right] Link to comment Share on other sites More sharing options...
martin Posted November 23, 2008 Share Posted November 23, 2008 (edited) 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 November 23, 2008 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 More sharing options...
autoitter Posted November 23, 2008 Author Share Posted November 23, 2008 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 More sharing options...
toonboon Posted November 23, 2008 Share Posted November 23, 2008 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 More sharing options...
autoitter Posted November 23, 2008 Author Share Posted November 23, 2008 Got it! This is it: $strReceived = StringRegExpReplace($strReceived, "\r([^\n])", @CRLF & "\1") Thanks martin and toonboon! Link to comment Share on other sites More sharing options...
gruntydatsun Posted January 19, 2018 Share Posted January 19, 2018 (edited) I came up with something slightly different $fixed = StringRegExpReplace($text,"(?m)\R{2,}",@CRLF) it works without the ?m too $fixed = StringRegExpReplace($text,"\R{2,}",@CRLF) Edited January 19, 2018 by gruntydatsun better answer Link to comment Share on other sites More sharing options...
iamtheky Posted January 19, 2018 Share Posted January 19, 2018 stringreplace(StringReplace($text , @CR , @CRLF) , @LF & @LF , @LF) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now