Jump to content

Recommended Posts

Posted

I want to remove all characters in a string, from an Asterisk to the end of the string, but the End Of Line regular expression character ('$') does not work for me.

$pat =  "[*]$"
consolewrite("+++: " &  StringRegExpReplace("D:\Temp\File.txt * 2abc def" ,$pat, "") & @CRLF
$pat =  "[*]"
consolewrite("+++: " &  StringRegExpReplace("D:\Temp\File.txt * 2abc def" ,$pat, "") & @CRLF

results in:
+++:  D:\Temp\File.txt * 2abc def
+++:  D:\Temp\File.txt  2abc def

I expected the first result to be: "+++: D:\Temp\File.txt "

(The second result just removed the Asterisk, as I expected.)

I tried \z and \Z, but they didn't work either.

Posted

Thanks for the example.

My problem was that my expression said look for an Asterisk AT the end of the line:

"[*]$"

What I need was an expression that said look for an Asterisk followed by zero or more characters up to the end of the line:

"[*].*$"

Posted

Correct, I think I was confused because you also mentioned EOL.

With the (?m) modifier it will match any line ending, without the flag it matches the end of the string just like z.

You could also write it like this:

*.*

which will match the first * it encounters and anything after it, and since this match is gready that means it will match to the end of the string.

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
×
×
  • Create New...