Our new official repo is on github
LCD Smartie version 5.6 is released!
Download it now: https://github.com/LCD-Smartie/LCDSmartie/releases

RegExp - Regular Expressions for LCD Smartie

Announcements of new plugins or updates.

Moderators: _X7JAY7X_, caesar, IFR, mattcro, limbo

Post Reply
ReverseEngineered
Plugin Author
Posts: 192
Joined: January 18th, 2006, 11:09 pm
Location: Saskatoon, Saskatchewan, Canada

RegExp - Regular Expressions for LCD Smartie

Post by ReverseEngineered »

link: regexp-1.0.zip

Good news LCD Smartie users, we now have one of the most powerful tools known to man, Regular Expressions!

I'm sure many of you are going, "What the f*&$ is a regular expression?" Well, it's a very thorough (if not complicated and cryptic) language for expressing patterns. These patterns can be used for many things: search and replace, creating substrings, reformatting strings, and counting occurances of patterns--just to name a few!

All of these functions are available within this plugin. For information on how to use the plugin, check the included readme.txt. To learn about regular expressions, check http://www.regular-expressions.info/.

What can you do with this?
- Pick out small numbers or sections from long strings (similar to cut.dll, but much more powerful!)
- Check for the presence of strings within strings (great for making actions that depend on a line in a large file)
- Perform advanced replacements--regex's specialty! Similar to sandr.dll, but able to match more than just simple strings.

What do I use this for?
- Reformatting the horrendously verbose string generated from weather RSS feeds.
- Making $TrackTitle (and other media player commands) output EXACTLY what I want to see.
- Displaying specific lines from a text file (using $File), even when I don't know where in the file those lines occur!


Since it is built on the C++ Regex Engine, this plugin has been released under the GNU General Public License (GPLv2). You are free to use it for personal or commercial purposes, and may distribute it freely, as long as the license and source code accompany it. You may also use it in your own derivative works, so long as you adopt the same license and make the source code freely available.
You do not have the required permissions to view the files attached to this post.

ReverseEngineered
Plugin Author
Posts: 192
Joined: January 18th, 2006, 11:09 pm
Location: Saskatoon, Saskatchewan, Canada

Post by ReverseEngineered »

One example of what regular expressions can do:
splittitle.dll lets you take "Beck - Where It's At" and seperate out the words. You can do the same thing with regular expressions!

Code: Select all

$dll(splittitle.dll,1,$WinampTitle,3)
$dll(splittitle.dll,2,$WinampTitle,3)
can be replaced by

Code: Select all

$dll(regexp.dll,1,.*(?= - ),$WinampTitle)
$dll(regexp.dll,1,(?<= - ).*,$WinampTitle)
"But this looks more complicated!" Yes, in this case it does take a little more work. However, it can do much more. For example, it can also handle strings like this:
"Various Artists - Beck / Where It's At"
It can even do this at the same time! How?

Code: Select all

$dll(regexp.dll,1,(?<=Various Artists - ).*(?= / )|.*(?= - ),$WinampTitle)
$dll(regexp.dll,1,(?<= / ).*|(?<= - ).*,$WinampTitle)
Of course, nobody said it was easy, but it can do very powerful things indeed!

Also, for complicated matches like this, the "split" function has been provided. Rather than taking the entire match, it only takes the parts that are in "groups". This way we can avoid the cumbersome (and limited) lookarounds I used above.

How's this for simple?

Code: Select all

$dll(regexp.dll,2,Various Artists - (.*) /|(.*) - ,$WinampTitle)
$dll(regexp.dll,2,Various Artists - .* / (.*)| - (.*),$WinampTitle) 
Not only is this simpler, but more powerful too. It ensures that Various Artists really was present when it tries to grab the song title. It's possible for the former code to accidently use this if a / is present in an otherwise normal title.

As you can see, regular expressions are great for doing advanced matches, the kind you just couldn't hope to do with plain old search and replace functions, even with wildcards.


Be sure to look back as I come up with more great regular expressions for using in sticky situations.

ReverseEngineered
Plugin Author
Posts: 192
Joined: January 18th, 2006, 11:09 pm
Location: Saskatoon, Saskatchewan, Canada

Post by ReverseEngineered »

Another great regex:

I dislike the way that $WinampResh lists only the seconds when there is less than a minute left. My solution? Add a "0:" in front and remove it if necessary! Here it is:

Code: Select all

-$dll(regexp,3,0:(\d*):#\1:,0:$WinampResh)
The result is something like -4:59 with lots of time left, and -0:23 if there is little time left. Works like a charm, and took 10 seconds to write.

Another problem:

Many songs have extra parts to their title in parenthesis afterwards. I want to keep them, but they take up too much room on the LCD. The solution?

Code: Select all

$dll(regexp,2,([^()]*).* - ,$WinampTitle)
$dll(regexp,2, - ([^()]*),$WinampTitle)

krisp
Plugin Author
Posts: 51
Joined: February 17th, 2006, 4:53 am

Post by krisp »

Great work. How does it handle multiple groupings? Does it return a concatinated list of everything you put in grouping symbols or do it only match the first?

ReverseEngineered
Plugin Author
Posts: 192
Joined: January 18th, 2006, 11:09 pm
Location: Saskatoon, Saskatchewan, Canada

Post by ReverseEngineered »

It depends on what function you use. Match will only take group 0; the entire matching string. Split will take all of the other groups (that aren't empty) and concatenate these with the seperator inbetween. For some complicated matches this can be more useful than Match. For the most control, Replace lets you specify exactly what groups end up where in the output. The names of the functions can be misleading, because, though the names specify the typical uses, they may work better for different tasks. You'll note that in my examples I have made varied use of all the functions.

Some of the examples may have errors. Sometimes one doesn't consider a special case that fails and requires some rethinking. However, I've yet to run into a problem that I can't solve using it.


(Besides, it's C++, not .NET, so it's only 340kb and loads REALLY fast ;))

limbo
Plugin Author
Posts: 1604
Joined: February 13th, 2005, 7:38 pm
Location: Athens - Greece
Contact:

Post by limbo »

ReverseEngineered wrote:One example of what regular expressions can do:
splittitle.dll lets you take "Beck - Where It's At" and seperate out the words. You can do the same thing with regular expressions!

Code: Select all

$dll(splittitle.dll,1,$WinampTitle,3)
$dll(splittitle.dll,2,$WinampTitle,3)
can be replaced by

Code: Select all

$dll(regexp.dll,1,.*(?= - ),$WinampTitle)
$dll(regexp.dll,1,(?<= - ).*,$WinampTitle)
"But this looks more complicated!" Yes, in this case it does take a little more work. However, it can do much more. For example, it can also handle strings like this:
"Various Artists - Beck / Where It's At"
It can even do this at the same time! How?

Code: Select all

$dll(regexp.dll,1,(?<=Various Artists - ).*(?= / )|.*(?= - ),$WinampTitle)
$dll(regexp.dll,1,(?<= / ).*|(?<= - ).*,$WinampTitle)
Of course, nobody said it was easy, but it can do very powerful things indeed!

Also, for complicated matches like this, the "split" function has been provided. Rather than taking the entire match, it only takes the parts that are in "groups". This way we can avoid the cumbersome (and limited) lookarounds I used above.

How's this for simple?

Code: Select all

$dll(regexp.dll,2,Various Artists - (.*) /|(.*) - ,$WinampTitle)
$dll(regexp.dll,2,Various Artists - .* / (.*)| - (.*),$WinampTitle) 
Not only is this simpler, but more powerful too. It ensures that Various Artists really was present when it tries to grab the song title. It's possible for the former code to accidently use this if a / is present in an otherwise normal title.

As you can see, regular expressions are great for doing advanced matches, the kind you just couldn't hope to do with plain old search and replace functions, even with wildcards.


Be sure to look back as I come up with more great regular expressions for using in sticky situations.



Hey Rev I missed this post :D
Are you trying to get us MAD? :smt103

I'm already "loco" I'm not afraid... :)
Great job keep on
Last edited by limbo on March 9th, 2006, 7:44 am, edited 1 time in total.

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

I've been playing around with regexp to format the playing time from winamp as per the examples in this thread. However, I wasn't happy with the formatting when the playing time is at less than 10 seconds. The example above gives "0:3" at 3 seconds, for example, which isn't what you'd expect to see on a clock.

After some head-scratching (I have zero experience with regexps!) I came up with:

Code: Select all

$dll(regexp,3,0:(\d*):#\1:#:(\d)#:0\1#0(\d\d)#\1,0:$WinampPosh)
to show the current playback time formatted like a digital clock. When the track is at the beginning (0 seconds) the output is "0:00". I nested this inside a $Right(...,$5%) to keep it in place on the screen, so it sits nicely next to my custom character play/pause/stop symbol.

It's perhaps not the most elegant way to do it, but I don't really know any better...

Matt.

PS my winamp screen now looks like this (16x2 LCD):

Code: Select all

*** $WinampTracknr: $WinampTitle 

$dll(sandr.dll,1,$WinampStat,) $Right($dll(regexp,3,0:(\d*):#\1:#:(\d)#:0\1#0(\d\d)#\1,0:$WinampPosh),$5%) $Fill(10)$WinampKBPSk
The WinampStat search-and-replace does the custom-char symbol (as per other posts)

ReverseEngineered
Plugin Author
Posts: 192
Joined: January 18th, 2006, 11:09 pm
Location: Saskatoon, Saskatchewan, Canada

Post by ReverseEngineered »

Thank you for the update mattcro. I hadn't actually tested (or even considered) what would happen below 10 seconds. Thank you for correcting this oversight. I could probably simplify things a bit, but if it works, by all means, use it.

DJ-Q
Posts: 5
Joined: December 8th, 2006, 11:57 am

Post by DJ-Q »

Hi

I have a txt file that I need to read and display information from that. The file is a log and looks like this:

Code: Select all

ID         Path                                    User name            # Locks 

------------------------------------------------------------------------------- 
8785859    D:\Data\...\E-mail\Outlook.pst          USER1        3      
8785920    D:\Data\data-exchange                   USER1        0      
8786829    D:\Data\sage\LINE100\Line100W.exe       USER2       0      
8786830    D:\Data\sage\LINE100\L100HOOK.dll       USER2       0      
8786831    D:\Data\sage\LINE100\L100RLST.DLL       USER2       0      
8786882    D:\Data\sage\SVNDATA\LOGON.RND          USER2       2      
8786883    D:\Data\sage\SVNPROGS\catalog.rel       USER2       0      
8786884    D:\Data\sage\SVNPROGS\catmst0.rin       USER2       0      
8795891    D:\Data\...\CAD\Standard Parts\Pipes    USER1        0      
8823338    D:\Data\sage\LINE100\Line100W.exe       USER3          0      
8823339    D:\Data\sage\LINE100\L100HOOK.dll       USER3          0      
8823340    D:\Data\sage\LINE100\L100RLST.DLL       USER3          0      
8823783    D:\Data\sage\SVNDATA\LOGON.RND          USER3          2      
8876648    D:\Data\sage\SVNDATA\SALMASTE.RIN       USER4        0      
8876649    D:\Data\sage\SVNDATA\SALMASTD.RIN       USER4        0      
8876650    D:\Data\sage\SVNDATA\SALMASTG.RIN       USER4        0      
The command completed successfully. 
What I need to do is read this log file for all users with D:\Data\sage\LINE100\Line100W.exe next to their name and then I want to display a scrolling list of those users on my LCD display, so in this example my LCD screen would show

* USER2 * USER3 *

Could somebody please help guide me in the right direction to acheive this?

Thanks

DJ-Q
Posts: 5
Joined: December 8th, 2006, 11:57 am

Post by DJ-Q »

DJ-Q wrote:Hi

I have a txt file that I need to read and display information from that. The file is a log and looks like this:

Code: Select all

ID         Path                                    User name            # Locks 

------------------------------------------------------------------------------- 
8785859    D:\Data\...\E-mail\Outlook.pst          USER1        3      
8785920    D:\Data\data-exchange                   USER1        0      
8786829    D:\Data\sage\LINE100\Line100W.exe       USER2       0      
8786830    D:\Data\sage\LINE100\L100HOOK.dll       USER2       0      
8786831    D:\Data\sage\LINE100\L100RLST.DLL       USER2       0      
8786882    D:\Data\sage\SVNDATA\LOGON.RND          USER2       2      
8786883    D:\Data\sage\SVNPROGS\catalog.rel       USER2       0      
8786884    D:\Data\sage\SVNPROGS\catmst0.rin       USER2       0      
8795891    D:\Data\...\CAD\Standard Parts\Pipes    USER1        0      
8823338    D:\Data\sage\LINE100\Line100W.exe       USER3          0      
8823339    D:\Data\sage\LINE100\L100HOOK.dll       USER3          0      
8823340    D:\Data\sage\LINE100\L100RLST.DLL       USER3          0      
8823783    D:\Data\sage\SVNDATA\LOGON.RND          USER3          2      
8876648    D:\Data\sage\SVNDATA\SALMASTE.RIN       USER4        0      
8876649    D:\Data\sage\SVNDATA\SALMASTD.RIN       USER4        0      
8876650    D:\Data\sage\SVNDATA\SALMASTG.RIN       USER4        0      
The command completed successfully. 
What I need to do is read this log file for all users with D:\Data\sage\LINE100\Line100W.exe next to their name and then I want to display a scrolling list of those users on my LCD display, so in this example my LCD screen would show

* USER2 * USER3 *

Could somebody please help guide me in the right direction to acheive this?

Thanks

Hello? Surely somebody can help me with the right sntax to achieve this??

usling
Posts: 38
Joined: September 5th, 2008, 1:55 pm

Re: RegExp - Regular Expressions for LCD Smartie

Post by usling »

I sometimes get a bug when i use this plugin. Errormessage says:

Load of plugin failed: loadlibrary failed with #998: invalid access to memory location.

i use win vista business 32bit. I've found that restarting lcdsmartie and closing all other programs doesn't help, reboot is the only solution. Error seams to occur randomly when vista starts, but i only get the errormessage when i start winamp and plays a song (when LCDsmartie shows my winamp screen). My VFD module then says: [Dll: Can not load plugin} where this info is supposed to be:

$dll(regexp,3,0:(\d*):#\1:#:(\d)#:0\1#0(\d\d)#\1,0:$WinampPosh)


i dug up some info about this error, but i know nothing about programming so i can't fix it myself :(
http://www.codeguru.com/forum/archive/i ... 64944.html
http://www.google.se/search?q=loadlibra ... =firefox-a


shame on such a great plugin :cry:

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Re: RegExp - Regular Expressions for LCD Smartie

Post by mattcro »

After making a small change to my Winamp title display ("Artist - Album - Title" instead of the default "Artist - Title"), I had to have another look at RegExp...

I now want artist/album/title on the LCD too

To get Artist (ie everything before the first occurrence of " - "):

Code: Select all

$dll(regexp.dll,1,.*?(?= - ),$WinampTitle)
To get Album (ie everything after the first occurrence of " - " but before the last " - "):

Code: Select all

$dll(regexp.dll,3,.*? - (.*?) - .*#\1,$WinampTitle)
To get Song Title (ie everything after the last occurrence of " - "):

Code: Select all

$dll(regexp.dll,3,.* - (.*)#\1,$WinampTitle)
These will cause problems if " - " occurs in your media tags, but it works well for me and avoids the issues in the splittitle plugin where extended/accented characters (any not in the standard 0-127 ASCII set) get mangled due to ASCII-unicode conversions in the plugin.

Post Reply