Page 1 of 1

Readfile to Support RegEx.

Posted: 20 Oct 2010 08:46
by SkyFrontier
If readfile() could support regEx, I could scan a document after URLs instead of blindly cleaning off everything else. This could store matching results by separators like [crlf], [|] or [;] and combinations like [;<crlf>].
-or is this already possible and I'm speaking dumbness? If so, how?
I'm trying to achieve a similar effect to what this (fixed) script already does, but it seems to be limited to one paragraph only, with limited support to separators, too.

Code: Select all

"Open URL in clipboard"
   regexreplace $url, "<clipboard>", ".*(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?).*", "$1";
   text $url;
//disabled for test purposes:   open $url;
Thanks!

Re: Readfile to Support RegEx.

Posted: 20 Oct 2010 13:06
by Stefan
SkyFrontier wrote:-or is this already possible and I'm speaking dumbness?
ReadFile() doesn't need RegEx support.
ReadFile() just reads the file content.
Put this content into an $var and parse this var with RegEx:

$original = readfile("C:\Temp\test.txt");
$cleaned = regexreplace($original, "match", "replace");

See XY help > "Scripting Commands Reference" for more.

.

Re: Readfile to Support RegEx.

Posted: 20 Oct 2010 14:37
by Joso
sounds like a job for a good text editor - Note Tab Pro does search and replace with RegEx (and lots of other things)

Re: Readfile to Support RegEx.

Posted: 20 Oct 2010 15:19
by SkyFrontier
@Stefan: I saw the references prior to posting. Sometimes the key is knowing where to look for, or how to put stuff together...
@Joso: I'm doing the best I can to learn by both example and reading how to XYscript, that's why I discard external tools as much as I can (but thank you for the tip!). Besides, doing such tasks from inside XY allows me to change what I need to change as fast as I locate a file/bunch of files needing changing while I'm file managing, so it's a time saver solving stuff that way.