Page 1 of 1
Hello - first post, question on scripting
Posted: 21 Apr 2013 22:22
by sweet40
Hi all, hello world.
I am thinking on an easy mode xyplorer could retrieve all tokens which met a certain condition.
alltokens, "parameter 1 - match start", "parameter 2 - match end", "return"
being "return" switches like
1, return to function
2, to clipboard
3, splash a 'text' containing all found tokens, paragraph-separated.
Re: Hello - first post, question on scripting
Posted: 21 Apr 2013 22:40
by highend
What examples do you have, where regexmatches() and a few extra lines don't do it's work?
Re: Hello - first post, question on scripting
Posted: 21 Apr 2013 23:44
by sweet40
For instance I'd like to get all tokens between "To:<crlf>" and ending with first ">" found:
header
...
To:
<Mom's Name>
Message
...
and the like.
"<Mom's Name" should be returned here, along with all other tokens metting the criteria.
Currently I get tokens pre and post "To:<crlf>", then I clean them but its cumbersome, boring and prone to fail.
Re: Hello - first post, question on scripting
Posted: 22 Apr 2013 12:36
by 40k
A common regular expression for catching data between delimiters is this:
To:[<][^>]*[>]
Read this as:
Find any sequence of characters starting with To: followed by < followed by any character that is not > followed by >
Note you may also write this as:
To:<[^>]*>
As the outer < and > are not a character class.
As I've done some extensive reading on this subject in connection with some of my scripts I'd like to recommend you Powergrep and a couple of the following links on Regexes:
http://www.debuggex.com/?re=&str=
http://www.zytrax.com/tech/web/regex.htm
http://www.regular-expressions.info/dot.html
Re: Hello - first post, question on scripting
Posted: 22 Apr 2013 12:46
by highend
Code: Select all
$test = <<<>>>
header
...
To:
<Daddy,Brother,Mom's Name>
Message
...
>>>;
$content = regexreplace(regexmatches($test, "To:\r\n<[^>]+", "|"), "To:\r\n<", "");
text $content;
And now you can proceed by a while / foreach loop or just get a single token out of it via gettoken().
Sorry, but I don't find one line of code to cumbersome.
Re: Hello - first post, question on scripting
Posted: 22 Apr 2013 12:48
by 40k
highend wrote:Code: Select all
$test = <<<>>>
header
...
To:
<Daddy,Brother,Mom's Name>
Message
...
>>>;
$content = regexreplace(regexmatches($test, "To:\r\n<[^>]+", "|"), "To:\r\n<", "");
text $content;
And now you can proceed by a while / foreach loop or just get a single token out of it via gettoken().
Sorry, but I don't find one line of code to cumbersome.
Won't that fail easily though?
Re: Hello - first post, question on scripting
Posted: 22 Apr 2013 12:52
by highend
Won't that fail easily though?
Why should it?
I can safely assume that a message will at least have one recipient, right?
Re: Hello - first post, question on scripting
Posted: 24 Apr 2013 14:28
by sweet40
Good reasons why I expect this function to be created:
1. regex-free: you just need to state the whole string needing strip, plus the boundaries. I'm definitely not a regex person.
2. easy: why one would need to put a whole section of code a single function could do?
3. fast: why one would need to put a whole section of code a single function could do?
Ok, I also had to look after a common token to split sections into, then loop into foreach. But what happens when no such a token is found?
40k: I tried to put regexmatch to work along your suggestion expecting it would return all tokens but I may have not understood the function yet.
highend: you saved my ass, thank you!
Re: Hello - first post, question on scripting
Posted: 24 Apr 2013 15:33
by Marco
sweet40 wrote:Hi all, hello world.
I am thinking on an easy mode xyplorer could retrieve all tokens which met a certain condition.
alltokens, "parameter 1 - match start", "parameter 2 - match end", "return"
being "return" switches like
1, return to function
2, to clipboard
3, splash a 'text' containing all found tokens, paragraph-separated.
sweet40 wrote:Good reasons why I expect this function to be created:
1. regex-free: you just need to state the whole string needing strip, plus the boundaries. I'm definitely not a regex person.
2. easy: why one would need to put a whole section of code a single function could do?
3. fast: why one would need to put a whole section of code a single function could do?
Ok, I also had to look after a common token to split sections into, then loop into foreach. But what happens when no such a token is found?
40k: I tried to put regexmatch to work along your suggestion expecting it would return all tokens but I may have not understood the function yet.
highend: you saved my ass, thank you!
The function you desire can be perfectly accomplished with regexmatches(). The only drawback is that currently the regex engine behind XY doesn't support lookaround constructs... If so running
Code: Select all
regexmatches($your-text,(?<="match_start").*?(?="match_end"),"<crlf>")
would do the trick. With another command you could either print it on screen (text), return it to functions by saving it in a variable, or pasting it to clipboard with copytext.
A good programmer wouldn't expect functions that do a lot of things because you conversely lose flexibility and granularity...
PS: regex are one of the most powerful things in scenarios you describe.
Re: Hello - first post, question on scripting
Posted: 28 Apr 2013 17:18
by sweet40
Is it possible this can be implemented, admin?
I badly need such a thing almost every day.
Re: Hello - first post, question on scripting
Posted: 28 Apr 2013 20:47
by admin
Didn't Marco post a solution?
Re: Hello - first post, question on scripting
Posted: 28 Apr 2013 21:21
by Marco
admin wrote:Didn't Marco post a solution?
Nope, because afaics XY regex engine doesn't support lookaround
Code: Select all
$testo = "My <b>cat</b> is furry";
$regex = "(?<=<b>)\w+(?=</b>)";
text regexmatches("$testo","$regex"); //should return "cat" (without quotes)
gives an error.
Btw, you can emulate lookaround by first finding the
<b>cat</b>'s with regexmatches and then stripping the outer marking with replacelist or regexreplace.
Re: Hello - first post, question on scripting
Posted: 28 Apr 2013 21:36
by admin
I don't have the desired functionality anywhere in my source code, hence I conclude it is alien to file management. And I think highend has shown that it can be done with scripting already.
Re: Hello - first post, question on scripting
Posted: 29 Apr 2013 01:23
by sweet40
Yes, but there's the hard and the easy way of doing stuff and when I saw some functions on XY i thought I could use readfile on a series of plain text databases to retrieve data like
Code: Select all
...
"20040imp.jsG:\Comix320LittleNemo\Garfield\Site\30years_1451631_files\ff2_data\st_data1457130034394141482137600300343941414821376"
"20040q.gifG:\Comix320LittleNemo\Garfield\Site\30years_1451631_files\ff2_data\st_data43130034394141482137600300343941414821376"
"20030970dfec473c9e448603c93b62314810.swfG:\Comix320LittleNemo\Garfield\Site\30years_1451631_files\st_data27135130034394141482137600300343941414821376"
"20040imp.jsG:\Comix320LittleNemo\Garfield\Site\30years_1451631_files\st_data1301130034394141482137600300343941414821376"
"20030a.htmG:\Comix320LittleNemo\Garfield\Site\30years_details_1451631_files11369130034394149482137600300343941494821376"
"20030action-download.gifG:\Comix320LittleNemo\Garfield\Site\30years_details_1451631_files86130034394149482137600300343941494821376"
...
and programmatically select only the files created on 2003, then do the expected file management.
I agree some of you may master some tricks and yawn at my necessity. I just thought I could do this using your engine.
My initial example may be bad, but at least it would be easier to explain what I want rather than exposing those cryptic data which in case is irrelevant to the desired principle: obtaining data using simple commands, easy for us neophytes to understand.
Sorry.
Re: Hello - first post, question on scripting
Posted: 29 Apr 2013 15:36
by Marco
sweet40 wrote:Yes, but there's the hard and the easy way of doing stuff and when I saw some functions on XY i thought I could use readfile on a series of plain text databases to retrieve data like
Code: Select all
...
"20040imp.jsG:\Comix320LittleNemo\Garfield\Site\30years_1451631_files\ff2_data\st_data1457130034394141482137600300343941414821376"
...
and programmatically select only the files created on 2003, then do the expected file management.
I agree some of you may master some tricks and yawn at my necessity. I just thought I could do this using your engine.
My initial example may be bad, but at least it would be easier to explain what I want
rather than exposing those cryptic data which in case is irrelevant to the desired principle: obtaining data using simple commands, easy for us neophytes to understand.
Sorry.
Well, by posting the cryptic data someone might be able to
teach you fishing...
Code: Select all
$data = readfile("FULL PATH TO THE TEXT FILE CONTAINING CRYPTIC DATA"); //pag 401 of pdf help file, located at http://www.xyplorer.com/download/XYplorerHelp.pdf
$list = regexmatches('^"2003.*', "$data", "<crlf>"); //pag 404 ...
text $list; //pag 452 ...
This shows in a window all the lines starting with
"2003, one line per line.