INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Regex - return everything to the right of pattern  (Read 4000 times)

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Regex - return everything to the right of pattern
« on: July 25, 2013, 07:49:52 pm »

Hey,

I'm hoping for some regex help.  I did a quick search and didn't quite find what I need and had a hard time with trying to get MC to do what I want with regex.  I have a bunch of folders named like: artistname2013-01-01.source.flac16.  I tried to use the ListItem pieces to return the source part of that string, but there are cases where I have folders named artistname2013-01-01.part.of.source.flac16.  In case #1 I want MC to return source.flac16 and #2 I want part.of.source.flac16.  Ideally I'd like just the source piece and not the flac16/flac24, but that seems easy to identify and remove.  I can't reliably go for the first iteration in a list of "." because I have some named artistname2013.01.01.source.flac16.

I figure this means I need to rely on regex to find a pattern of [1900-2100](-or.)[00-12](-or.)[00-31] and then return everything to the right of that in the string.

Any help would be appreciated!  Thanks,

--Ryan
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Regex - return everything to the right of pattern
« Reply #1 on: July 25, 2013, 08:25:11 pm »

I used the comment field to test.  Here's the expression:

   regex([comment], /#((?:part\.of\.)?source)\.flac\d+#/, 1)

See attached.
Logged
The opinions I express represent my own folly.

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Regex - return everything to the right of pattern
« Reply #2 on: July 25, 2013, 08:30:21 pm »

I used the comment field to test.  Here's the expression:

   regex([comment], /#((?:part\.of\.)?source)\.flac\d+#/, 1)

See attached.

That works with the examples, but perhaps I was coming across too literally.  Here's what a sample of what one of the directories looks like.  The source could be any text, which is why I was thinking I'd key it off of the pattern of yyyy-mm-dd first.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Regex - return everything to the right of pattern
« Reply #3 on: July 25, 2013, 08:32:42 pm »

So you want everything after the date and before the flac\d\d, right ?
Logged
The opinions I express represent my own folly.

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Regex - return everything to the right of pattern
« Reply #4 on: July 25, 2013, 08:35:45 pm »

So you want everything after the date and before the flac\d\d, right ?

Yup.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Regex - return everything to the right of pattern
« Reply #5 on: July 25, 2013, 08:36:20 pm »

regex([comment], /#\d{4}-\d{2}-\d{2}\.(.+?)\.flac\d+#/, 1)
Logged
The opinions I express represent my own folly.

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Regex - return everything to the right of pattern
« Reply #6 on: July 25, 2013, 08:38:45 pm »

regex([comment], /#\d{4}-\d{2}-\d{2}\.(.+?)\.flac\d+#/, 1)

Ah, I think that makes sense...  This is what I have somewhere else to get the date (grabbed from the wiki):

Regex([Filename (path)],/#(\d{4})\-(\d{1,2})\-(\d{1,2})#/,-1)[R1]-[R2]-[R3]

So the (+?) just signifies everything that matches a wildcard pattern?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Regex - return everything to the right of pattern
« Reply #7 on: July 25, 2013, 08:43:09 pm »

The ? after a quantifier means to disable Greediness.

.* will get 0 or more characters
.+ will get 1 or more characters
.*? will get 0 or more characters, but as few as possible
.+? will get 1 or more characters, but as few as possible

Generally, regular expressions are Greedy.  So long as a pattern matches, the RE engine will keep consuming.

Often you only want to grab the first piece of something, leaving later patterns to match.
Logged
The opinions I express represent my own folly.

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Regex - return everything to the right of pattern
« Reply #8 on: July 25, 2013, 08:46:58 pm »

The ? after a quantifier means to disable Greediness.

.* will get 0 or more characters
.+ will get 1 or more characters
.*? will get 0 or more characters, but as few as possible
.+? will get 1 or more characters, but as few as possible

Generally, regular expressions are Greedy.  So long as a pattern matches, the RE engine will keep consuming.

Often you only want to grab the first piece of something, leaving later patterns to match.

Ok... That sort of makes sense, ha.  It works, so you're right, but I'm just slow when it comes to expression searches.

Thanks!

--Ryan
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Regex - return everything to the right of pattern
« Reply #9 on: July 25, 2013, 08:49:43 pm »

Great!

By the way, does "hoyt" signify anything (other than maybe a first name)?

For some odd reason, my family used to call that just-out-of-the-oven crisp roasted turkey skin "the hoyt", and they fought over the coveted, salty delicacy.  Strange birds they were.  :-)
Logged
The opinions I express represent my own folly.

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Regex - return everything to the right of pattern
« Reply #10 on: July 25, 2013, 08:55:24 pm »

Great!

By the way, does "hoyt" signify anything (other than maybe a first name)?

For some odd reason, my family used to call that just-out-of-the-oven crisp roasted turkey skin "the hoyt", and they fought over the coveted, salty delicacy.  Strange birds they were.  :-)

Last name.  Were they hunters that brought in the turkey earlier in the day?  www.hoyt.com  Sounds like at Thanksgiving you need to get some "Get serious, get Hoyt" accessories. 
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Regex - return everything to the right of pattern
« Reply #11 on: July 25, 2013, 08:59:26 pm »

The only thing they hunted was a good bargain at the supermarket.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up