Jump to content

StringRegExpReplace


anixon
 Share

Recommended Posts

I have a string which looks like this:

aaaa<space>123456<crlf>

bbbb:<space>1234<space>1234<space>1234<space>1234<crlf>

cccc:<space>This is text

Which I want to convert to this:

aaaa|123456|bbbb:|1234|1234|1234|1234|cccc:|This is text

This code does not work:

$Text = StringRegExpReplace($String, "\s+", "|")

and neither does this work:

$Text = StringRegExpReplace($String, "[\r\n]+", "|")
$Text = StringReplace($Text, " ", "|")

Assistance is always appreciated Ant.. :)

Link to comment
Share on other sites

I have a string which looks like this:

aaaa<space>123456<crlf>

bbbb:<space>1234<space>1234<space>1234<space>1234<crlf>

cccc:<space>This is text

Which I want to convert to this:

aaaa|123456|bbbb:|1234|1234|1234|1234|cccc:|This is text

This code does not work:

$Text = StringRegExpReplace($String, "\s+", "|")

and neither does this work:

$Text = StringRegExpReplace($String, "[\r\n]+", "|")
$Text = StringReplace($Text, " ", "|")

Assistance is always appreciated Ant.. :)

If the string is as you have written it then there is no \r\n to replace because these are represented by <crlf>

But I suspose you have just done that so we can see them.

Assuming there really is @CRLF there instead of <crlf> and a space instead of <space> then your RegExp examples work.

Either way I think in this case it is easier to use StringReplace

$Text = STringReplace($Text,'<crlf>','|')
$Text = STringReplace($Text,'<space>','|')
;OR
$Text = STringReplace($Text,@CRLF,'|')
$Text = STringReplace($Text,' ','|')
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

If the string is as you have written it then there is no \r\n to replace because these are represented by <crlf>

But I suspose you have just done that so we can see them.

Assuming there really is @CRLF there instead of <crlf> and a space instead of <space> then your RegExp examples work.

Either way I think in this case it is easier to use StringReplace

$Text = STringReplace($Text,'<crlf>','|')
$Text = STringReplace($Text,'<space>','|')
;OR
$Text = STringReplace($Text,@CRLF,'|')
$Text = STringReplace($Text,' ','|')

The text is contained within an email when copied to Word the formatting marks representing a <space> are either a degree mark <as in degrees minutes> as well as what looks like a hyphen. They marks do not alternate and appear randomly between each character

This code will convert the degrees to "|" but not the other formatting mark '-'

MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($text, "[\s ]+", "|"))
Link to comment
Share on other sites

$sText = StringRegExpReplace($sText, "(\s+), "|")

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

$sText = StringRegExpReplace($sText, "(\s+), "|")

The embedded code [viewed in Word] within the email text for a space can be either the degree symbol [as in degrees minutes] or what looks like a hyphen '-' your code will convert the '-' representing a space to "|" but not the degree symbol representing a space.
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...