SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-29-2010, 07:42 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
RegEX help

Okay trying to better understand regex and all its powers

First I am not a regex fan I realize how powerful it is but I suck at it to put it bluntly.

I am using this site to try and help me along the way. I am looking for a way to build regex patters for typing on the remote to match all letters. Say the user pushes number 2 and number 3. I want it to match against [a,b,c] and [d,e,f] and return all possible matches/combination of the two. ie ad,ae,af,bd,be,bd,cd,ce,cf. I want to continue building this regex based on how many numbers they push. Sort of like smart texting. I thought I read sage did something similar in the advanced functions but I don't use those so if someone wants to point me in that direction that would be ok too.

TIA
Reply With Quote
  #2  
Old 10-29-2010, 07:59 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Phoenix has an API for that

phoenix_util_CreateRegexFromKeyPad

You feed it your keypad entry, and it will return a java regex.

You could write your own, but I suggest depending on the phoenix-api and just use that one.
Reply With Quote
  #3  
Old 10-29-2010, 08:04 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
Phoenix has an API for that

phoenix_util_CreateRegexFromKeyPad

You feed it your keypad entry, and it will return a java regex.

You could write your own, but I suggest depending on the phoenix-api and just use that one.
Well thanks...

That doesn't do much for helping me learn , but none the less will work.

Off to sneak a peak at the code
Reply With Quote
  #4  
Old 10-29-2010, 08:16 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
In looking at your return I was so close...yet so far I as stupidly forgetting to put the CAPS versions in there...oh well just use your method as it is done

cheers
Reply With Quote
  #5  
Old 10-29-2010, 11:48 AM
evilpenguin's Avatar
evilpenguin evilpenguin is offline
SageTVaholic
 
Join Date: Aug 2003
Location: Seattle, WA
Posts: 3,696
RegEx's are lots of fun. For beginners I recommend Learning Perl from O'Reilly publishing. Its got a great section on RegEx basics and its a lot easier to play around with them in a scripting language like Perl rather than one that needs to be compiled like Java.

Those basics will get you pretty far, but if you really want to be one of the cool kids you can also upgrade to Regular Expression Pocket Reference from O'Reilly which will pretty much forge you into a RegEx ninja master, much like myself
__________________
Clients: 1xHD200 Connected to 50" TH-50PZ750U Plasma
Server : Shuttle SFF SSH55J2 w/ Win7 Home, SageTV v7, Core i3 540, 2GB RAM, 30GB SSD for OS, 1.5TB+2x1TB WDGP for Recordings, BluRay, 2xHDHR, 1xFirewire
SageTV : PlayOn, SJQ, MediaShrink, Comskip, Jetty, Web Client, BMT


Having a problem? Don't forget to include a log! (Instructions for: PlayOn For SageTV v1.5, MediaShrink)
Reply With Quote
  #6  
Old 10-29-2010, 11:50 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by evilpenguin View Post
RegEx's are lots of fun. For beginners I recommend Learning Perl from O'Reilly publishing. Its got a great section on RegEx basics and its a lot easier to play around with them in a scripting language like Perl rather than one that needs to be compiled like Java.

Those basics will get you pretty far, but if you really want to be one of the cool kids you can also upgrade to Regular Expression Pocket Reference from O'Reilly which will pretty much forge you into a RegEx ninja master, much like myself
Thanks for the tips/pointers and I haven't ignored your email promise
Reply With Quote
  #7  
Old 10-29-2010, 11:58 AM
broconne broconne is offline
Sage Aficionado
 
Join Date: Feb 2009
Location: Cary, NC
Posts: 306
Quote:
Originally Posted by evilpenguin View Post
RegEx's are lots of fun.
I respectfully disagree :-)
__________________
Host: ESXi 6.5 w/ Intel Core i7 2.8GHZ 8GB Ram
Guest: Ubuntu 16.04 with Sage v9 in Docker
Tuners: 2 HDHR (OTA);
Extenders: HD300 connected to a Samsung 56" DLP HDTV; HD300 connected to a Sharp 42" LCD
Storage: OmniOS w/6 1TB Samsung Spinpoint in a RaidZ2 configuration in a 20 bay SATA hotswap case.
Reply With Quote
  #8  
Old 10-29-2010, 12:02 PM
evilpenguin's Avatar
evilpenguin evilpenguin is offline
SageTVaholic
 
Join Date: Aug 2003
Location: Seattle, WA
Posts: 3,696
$prevPost = s/dis/strongly /g;

See, we're having fun now!
__________________
Clients: 1xHD200 Connected to 50" TH-50PZ750U Plasma
Server : Shuttle SFF SSH55J2 w/ Win7 Home, SageTV v7, Core i3 540, 2GB RAM, 30GB SSD for OS, 1.5TB+2x1TB WDGP for Recordings, BluRay, 2xHDHR, 1xFirewire
SageTV : PlayOn, SJQ, MediaShrink, Comskip, Jetty, Web Client, BMT


Having a problem? Don't forget to include a log! (Instructions for: PlayOn For SageTV v1.5, MediaShrink)
Reply With Quote
  #9  
Old 10-29-2010, 12:21 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
I have to admit, I was never a fan of regular expressions, but over the years, I've learned that they can be tremendously helpful, and even a time saver. As a developer, I've written my share of text processors, and when I look back, regex could have saved me hours and hours of work

Just last week, I was working with a guy who had to process some data from an external source (web service), that happened to contain html code (that's just wrong). But he needed just the text, and not all the html tags. (the html was simple formatting for a description, that contained things like <b> and <i>, etc... ). He started talking about how he could write a processor that could find all the <tags>, and remove them... all in all, he figured no more than a couple of hrs work... I let him go on for a bit, explaining the process... then i got out a piece of paper and wrote on it....

text = text.replaceAll("<[^>]+>","")

And I walked away...

The thing is, regex has it's place. If you use it, for the right reasons, it will save your time. Now perl on the the other hand...
Reply With Quote
  #10  
Old 10-30-2010, 11:09 AM
broconne broconne is offline
Sage Aficionado
 
Join Date: Feb 2009
Location: Cary, NC
Posts: 306
The one problem I have had is their performance in Java. Even when you compile them and reuse, if you are doing simple text processing across a huge number of lines - they just can't keep up with a custom text processor. But that is to be expected.

Probably not going to be an issue with a sage plugin.
__________________
Host: ESXi 6.5 w/ Intel Core i7 2.8GHZ 8GB Ram
Guest: Ubuntu 16.04 with Sage v9 in Docker
Tuners: 2 HDHR (OTA);
Extenders: HD300 connected to a Samsung 56" DLP HDTV; HD300 connected to a Sharp 42" LCD
Storage: OmniOS w/6 1TB Samsung Spinpoint in a RaidZ2 configuration in a 20 bay SATA hotswap case.
Reply With Quote
  #11  
Old 10-30-2010, 11:55 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Yeah I don't see a sagetv user having enough movies in their databse to really notice the speed that bad...I am actually running them in SQL queries and although not the most efficient I would think it would take way more of a database size than sagetv users have to notice it.
Reply With Quote
  #12  
Old 10-30-2010, 12:07 PM
broconne broconne is offline
Sage Aficionado
 
Join Date: Feb 2009
Location: Cary, NC
Posts: 306
If you are using them as filters, specially if you are going to have multiple filters - you may want to look at the Google Collections Iterable/Predicate filtering mechanism. I have found it very useful before when filtering data.
__________________
Host: ESXi 6.5 w/ Intel Core i7 2.8GHZ 8GB Ram
Guest: Ubuntu 16.04 with Sage v9 in Docker
Tuners: 2 HDHR (OTA);
Extenders: HD300 connected to a Samsung 56" DLP HDTV; HD300 connected to a Sharp 42" LCD
Storage: OmniOS w/6 1TB Samsung Spinpoint in a RaidZ2 configuration in a 20 bay SATA hotswap case.
Reply With Quote
  #13  
Old 10-30-2010, 09:26 PM
david1234 david1234 is offline
Sage Aficionado
 
Join Date: Nov 2007
Location: Beaverton, OR
Posts: 313
Quote:
Originally Posted by PLUCKYHD View Post
In looking at your return I was so close...yet so far I as stupidly forgetting to put the CAPS versions in there...oh well just use your method as it is done

cheers
I learned regexes since VIM uses them for a search and replace functions.

I know you don't need it anymore, but the Pattern/Matcher combination works pretty well. No need to specify the upper and lower case, since the flag will take care of it.

Code:
String foo = "af";
Pattern pattern = Pattern.compile("[abc][def]", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(foo);
if (matcher.matches()) { doStuff(); }
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
parser regex question (replace?) cornasdf Batch Metadata Tools 3 10-18-2010 07:43 AM
Regex help for tv shows PLUCKYHD Batch Metadata Tools 4 05-23-2010 09:35 AM
RegEx for Favorites? matterw SageTV Software 2 01-23-2010 11:47 PM
Regex in Favorites??? zoundz SageTV Software 0 10-20-2008 10:56 AM


All times are GMT -6. The time now is 02:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.