Replacing "?" - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: Replacing "?" (/showthread.php?tid=74131) Replacing "?" by Jimbo on 05-03-2007 at 04:43 PM
I am trying to write something that replaces ? with ..? but to no success. RE: Replacing "?" by Ezra on 05-03-2007 at 05:01 PM
That's possible with a simple regex. code: RE: Replacing "?" by Jimbo on 05-03-2007 at 06:01 PM
oh ok RE: Replacing "?" by Matti on 05-03-2007 at 06:28 PM
quote:You forgot the "" around the second parameter. The first is a regular expression object and is totally correct, but the second is a string. Also, the regular expression can be lots and lots simpler. Therefore, the right way would be: code:Here, I don't let it capture everything before the question mark because it simply isn't needed. This gives you a much easier to understand regular expression without the need of inserting captured parameters! Because remember to KISS! (Keep It Short and Simple) RE: Replacing "?" by Ezra on 05-03-2007 at 07:02 PM
Thanks for fixing up my mistake RE: Replacing "?" by CookieRevised on 05-03-2007 at 10:50 PM
? What?!? RE: RE: Replacing "?" by deAd on 05-03-2007 at 10:57 PM
quote:No it won't. I assume you're talking about this one: code: Because it is not global, only one occurrence will be replaced, and since there is the $ at the end of it, only the last one. "? What?!?" turns into "? What?!..?". RE: Replacing "?" by CookieRevised on 05-03-2007 at 11:01 PM
true, example given wasn't that great. But then again... the string: RE: Replacing "?" by Matti on 05-04-2007 at 04:40 PM
What I did was fixing Ezra's given solution, I did not take the actual suggestion in account, and maybe that was a mistake from my side. Sorry for that. code:This example will replace all "?" with "..?" when they are preceded by an alphanumeric character (a-z, A-Z and 0-9) and followed by a white space character (new line, tab, space,...) OR the end of the string. Therefore, it's somewhat limited because it won't parse something like "Hello!?", but if you really need that too this can be fixed by using: code:but then, it'll also change "Hello!" into "Hello..!" and maybe you don't want that. To avoid that from happening, you'll need to go even further, but I'm not in the mood to do that now. |