Hello - first post, question on scripting
-
sweet40
- Posts: 84
- Joined: 21 Apr 2013 22:16
Hello - first post, question on scripting
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.
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.
-
highend
- Posts: 14956
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Hello - first post, question on scripting
What examples do you have, where regexmatches() and a few extra lines don't do it's work?
One of my scripts helped you out? Please donate via Paypal
-
sweet40
- Posts: 84
- Joined: 21 Apr 2013 22:16
Re: Hello - first post, question on scripting
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.
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.
-
40k
- Posts: 234
- Joined: 09 Dec 2011 21:25
Re: Hello - first post, question on scripting
A common regular expression for catching data between delimiters is this:
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:
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
Read this as:To:[<][^>]*[>]
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:
As the outer < and > are not a character class.To:<[^>]*>
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
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial
-
highend
- Posts: 14956
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Hello - first post, question on scripting
Code: Select all
$test = <<<>>>
header
...
To:
<Daddy,Brother,Mom's Name>
Message
...
>>>;
$content = regexreplace(regexmatches($test, "To:\r\n<[^>]+", "|"), "To:\r\n<", "");
text $content;Sorry, but I don't find one line of code to cumbersome.
One of my scripts helped you out? Please donate via Paypal
-
40k
- Posts: 234
- Joined: 09 Dec 2011 21:25
Re: Hello - first post, question on scripting
Won't that fail easily though?highend wrote:And now you can proceed by a while / foreach loop or just get a single token out of it via gettoken().Code: Select all
$test = <<<>>> header ... To: <Daddy,Brother,Mom's Name> Message ... >>>; $content = regexreplace(regexmatches($test, "To:\r\n<[^>]+", "|"), "To:\r\n<", ""); text $content;
Sorry, but I don't find one line of code to cumbersome.
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial
-
highend
- Posts: 14956
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Hello - first post, question on scripting
Why should it?Won't that fail easily though?
I can safely assume that a message will at least have one recipient, right?
One of my scripts helped you out? Please donate via Paypal
-
sweet40
- Posts: 84
- Joined: 21 Apr 2013 22:16
Re: Hello - first post, question on scripting
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!
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!
-
Marco
- Posts: 2354
- Joined: 27 Jun 2011 15:20
Re: Hello - first post, question on scripting
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.
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 runningsweet40 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!
Code: Select all
regexmatches($your-text,(?<="match_start").*?(?="match_end"),"<crlf>")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.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
-
sweet40
- Posts: 84
- Joined: 21 Apr 2013 22:16
Re: Hello - first post, question on scripting
Is it possible this can be implemented, admin?
I badly need such a thing almost every day.
I badly need such a thing almost every day.
-
admin
- Site Admin
- Posts: 66374
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Hello - first post, question on scripting
Didn't Marco post a solution?
FAQ | XY News RSS | XY X
-
Marco
- Posts: 2354
- Joined: 27 Jun 2011 15:20
Re: Hello - first post, question on scripting
Nope, because afaics XY regex engine doesn't support lookaroundadmin wrote:Didn't Marco post a solution?
Code: Select all
$testo = "My <b>cat</b> is furry";
$regex = "(?<=<b>)\w+(?=</b>)";
text regexmatches("$testo","$regex"); //should return "cat" (without quotes)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.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
-
admin
- Site Admin
- Posts: 66374
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Hello - first post, question on scripting
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.
FAQ | XY News RSS | XY X
-
sweet40
- Posts: 84
- Joined: 21 Apr 2013 22:16
Re: Hello - first post, question on scripting
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
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.
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"
...
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.
-
Marco
- Posts: 2354
- Joined: 27 Jun 2011 15:20
Re: Hello - first post, question on scripting
Well, by posting the cryptic data someone might be able to teach you fishing...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
and programmatically select only the files created on 2003, then do the expected file management.Code: Select all
... "20040imp.jsG:\Comix320LittleNemo\Garfield\Site\30years_1451631_files\ff2_data\st_data1457130034394141482137600300343941414821376" ...
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.
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 ...Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
XYplorer Beta Club