Re: Differential pattern match

Discussion in 'Perl Misc' started by Graham S, Oct 6, 2012.

  1. Graham S

    Graham S Guest

    "Ben Morrow" <> wrote in message
    news:...
    >
    > Quoth "Graham" <>:
    >>
    >> > / ((?: (?: \b [12][0-9] \b | [0-9Xx] ) [ ]{0,2} ){6}) /x did the
    >> > business and produces exactly the output I want !! (basically your code
    >> > with an additional pair of parentheses on the extreme left and right to
    >> > capture the output
    >> >
    >> > Tested it on a number of tabs with 100% success !!
    >> >
    >> > Apart from the following line - which I obviously wouldn't expect to
    >> > match
    >> > 8X998X 7X778X 6X776X 5X556X AXBBAX 9X99AX
    >> > 8X998X 7X778X 6X776X 5X556X AXBBAX
    >> > 9X99AXDon't
    >> > know what's going on there with the As and the B's - maybe it a typo,
    >> > or
    >> > maybe it means something I'm not aware of (I'm no guitarist either!)

    >
    > I presume you can see how to fix that, if you want to? (Just treat A and
    > B the same as X.)
    >
    >> Hmm - I spoke a little to soon! It's fine with a few of the 'commercial'
    >> tabs I've fed it, but when I try and break it, unfortunately I can with
    >> the
    >> likes of....
    >>
    >> It doesn't like this 'xx10 10 10x' very muchor this 'x10 10 10 9x'
    >> eitherwhich match as It doesn't like this 'xx10 10 10x' very muchor this
    >> 'x10 10 10 9x' eitherGraham

    >
    > Well, no. I didn't know those were allowed, either: they have a
    > single-character fret 'number' (which happens to be an X) right next to
    > a double-digit number, with no space. The only simple way I can see to
    > fix that is to replace the first \b with
    >
    > (?: (?<= [Xx]) | \b )
    >
    > and the second with
    >
    > (?: (?= [Xx]) | \b )
    >
    > Those constructions are called 'lookahead/behind', and like \b, ^ and $
    > they are zero-width assertions that match between characters. (?<=foo)
    > matches at a point in the string immediately preceded by 'foo', (?=foo)
    > at a point immediately followed. So the new pattern will allow Xs to
    > butt up against two-digit fret numbers, but not other digits or letters.
    >
    > This is turning into quite a complicated pattern. Make sure you write it
    > with plenty of whitespace (and newlines and indentation, where that's
    > helpful), and if necessary include comments within the pattern to
    > explain what the various bits do.
    >
    > Ben
    >

    Superb!! Works a treat!!
    I'm pretty convinced this will match 99.9% of guitar tabs out there - most
    of them are straightforward 6 character strings of X's and numerals played
    below the 10th fret anyway, but this pattern match should catch the vast
    majority of the more complex ones.
    And many thanks for explaining some of the finer points of pattern matching

    Graham
    Graham S, Oct 6, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hiwa
    Replies:
    0
    Views:
    631
  2. Victor
    Replies:
    2
    Views:
    629
    Victor
    May 17, 2004
  3. greg.smith

    solving differential equation

    greg.smith, Sep 22, 2003, in forum: C Programming
    Replies:
    3
    Views:
    422
    Bigdakine
    Sep 24, 2003
  4. Justin C

    Re: Differential pattern match

    Justin C, Oct 4, 2012, in forum: Perl Misc
    Replies:
    0
    Views:
    298
    Justin C
    Oct 4, 2012
  5. Graham S

    Re: Differential pattern match

    Graham S, Oct 4, 2012, in forum: Perl Misc
    Replies:
    7
    Views:
    367
    Rainer Weikusat
    Oct 12, 2012
Loading...

Share This Page