Jump to content

StringRegExpReplace


 Share

Recommended Posts

I would replace the end of a dynamic text. I have a txt file which change every day.

But at the last of the day, i would check the end of the file.

And while the text is different of "perf" and any digit and "final", he delete characters.

For exemple, my text file is "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"

I want have ""Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final" and delete " Logged 15:05 TCD=22118"

But same with examples in the help file and in the forum.... I BUG !

Thanks

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

I would replace the end of a dynamic text. I have a txt file which change every day.

But at the last of the day, i would check the end of the file.

And while the text is different of "perf" and any digit and "final", he delete characters.

For exemple, my text file is "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"

I want have ""Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final" and delete " Logged 15:05 TCD=22118"

But same with examples in the help file and in the forum.... I BUG !

Thanks

Maybe this does what you wnat.

$str = "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"
$ans = StringRegExp($str,"(Temp.*?final)",1)
if @error = 0 then
ConsoleWrite($ans[0] & @CRLF)
;I want have ""Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final"
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

I would replace the end of a dynamic text. I have a txt file which change every day.

But at the last of the day, i would check the end of the file.

And while the text is different of "perf" and any digit and "final", he delete characters.

For exemple, my text file is "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"

I want have ""Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final" and delete " Logged 15:05 TCD=22118"

But same with examples in the help file and in the forum.... I BUG !

Thanks

Oups.... :) In fact I want have "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final" and delete " Logged 15:05 TCD=22118"

Sorry...

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

Oups.... :) In fact I want have I want have "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final" and delete " Logged 15:05 TCD=22118"

Sorry...

Well just change it to what you want, you should be able to see how what I did worked, even if it means looking in the help.

$str = "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"
$ans = StringRegExp($str,"(Temp.*final.*final)",1);find something which consists of "Temp" followed by any number of characters, then "final" then any number of characters, then "final"
if @error = 0 then;if something was found
ConsoleWrite($ans[0] & @CRLF);show me what it was
EndIf
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

Well just change it to what you want, you should be able to see how what I did worked, even if it means looking in the help.

$str = "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"
$ans = StringRegExp($str,"(Temp.*final.*final)",1);find something which consists of "Temp" followed by any number of characters, then "final" then any number of characters, then "final"
if @error = 0 then;if something was found
ConsoleWrite($ans[0] & @CRLF);show me what it was
EndIf

Yes, the return value is almost this. But the start of the string must be unchanged.

==>> "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final"

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

Just change the line to:

$ans = StringRegExp($String, '("Temp.*final.*final")', 1)oÝ÷ ÚÚºÚ"µÍÌÍØ[ÈHÝ[ÔYÑ^
    ÌÍÔÝ[Ë ][ÝÊ  ][ÝÉ][ÝÕ[[[[[   ][ÝÉ][ÝÊI][ÝËJ

That's the only difference I see in what you want as output (the surrounding double quotes)

Link to comment
Share on other sites

Just change the line to:

$ans = StringRegExp($String, '("Temp.*final.*final")', 1)oÝ÷ ÚÚºÚ"µÍÌÍØ[ÈHÝ[ÔYÑ^
    ÌÍÔÝ[Ë ][ÝÊ  ][ÝÉ][ÝÕ[[[[[   ][ÝÉ][ÝÊI][ÝËJ

That's the only difference I see in what you want as output (the surrounding double quotes)

@varian: neither of those suggestions works.

@jerem488

If you just want to add quotation marks then

$str = "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"
$ans = StringRegExp($str,"(Temp.*final.*final)",1);find something which consists of "Temp" followed by any number of characters, then "final" then any number of characters, then "final"

If @error = 0 then;if something was found
  ConsoleWrite('"' & $ans[0] & '"' & @CRLF);show me what it was
EndIf

Otherwise I don't understand what you mean by "But the start of the string must be unchanged."

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

@varian: neither of those suggestions works.

@jerem488

If you just want to add quotation marks then

$str = "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"
$ans = StringRegExp($str,"(Temp.*final.*final)",1);find something which consists of "Temp" followed by any number of characters, then "final" then any number of characters, then "final"

If @error = 0 then;if something was found
  ConsoleWrite('"' & $ans[0] & '"' & @CRLF);show me what it was
EndIf

Otherwise I don't understand what you mean by "But the start of the string must be unchanged."

Very thanks Martin. But I have great difficulty understanding this function (StringRegExp).

Even your response I don't understand !

Thanks again

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

StringRegExpReplace() will return the changed string only

StringRegExp() will return the matches, the number of matches, and the change(s), depending on the flag

StringRegExpReplace('hot4teacher', \d', '#') returns hot#teacher

StringRegExp('hot4teacher', '\d', 1) returns an array of all matches, in this case, $array[0] = 4

StringRegExp('1a2b3c4d', '\d', 1) returns $array[0] = 1 $array[1]=2 $array[2]=3 $array[3]=4

Link to comment
Share on other sites

@varian: neither of those suggestions works.

@jerem488

If you just want to add quotation marks then

$str = "Temp 45 str ? Cleaning started at 15:30:41 perf 165841 final 2008/12/30-18:27:06.875 ServerLoad[] error=1073 perf 00001 final Logged 15:05 TCD=22118"
$ans = StringRegExp($str,"(Temp.*final.*final)",1);find something which consists of "Temp" followed by any number of characters, then "final" then any number of characters, then "final"

If @error = 0 then;if something was found
  ConsoleWrite('"' & $ans[0] & '"' & @CRLF);show me what it was
EndIf

Otherwise I don't understand what you mean by "But the start of the string must be unchanged."

I thought that the string being read already was surrounded by quotes because of the leading double quote in the first post:

"Temp 45 str ? Cleaning, etc."

Thats why I said to look for the quotes in my regexp

Link to comment
Share on other sites

StringRegExpReplace() will return the changed string only

StringRegExp() will return the matches, the number of matches, and the change(s), depending on the flag

StringRegExpReplace('hot4teacher', \d', '#') returns hot#teacher

StringRegExp('hot4teacher', '\d', 1) returns an array of all matches, in this case, $array[0] = 4

StringRegExp('1a2b3c4d', '\d', 1) returns $array[0] = 1 $array[1]=2 $array[2]=3 $array[3]=4

this does not answer the question. I understood what these functions served

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

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