#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    395
    Rep Power
    31

    Remove everything except letters and numbers


    I'm not a wiz at regexp. In fact I barely limp along as you can no doubt tell by the title.

    I have a python . . . <shrug> I don't even know what to call it. I'm using Calibre to manage my library and get the content correctly formatted to go to my reader. I am trying to prep the stripped book title to just letters and numbers for inclusion in the file name.

    {#stripped_title:re([a-z]+[A-Z]+[0-9]+,)} isn't giving me what I need. It gives me the title, but the spaces are still there. Apostrophes are still there. <whine>

    Can someone help me?

    Thanks.

    HeadElf
    HeadElf
    OfficeElf.com
  2. #2
  3. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    Hi HeadElf,

    Can you please provide one or two samples (two is better) of an original string and desired result string?

    Wishing you a beautiful day.

  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    395
    Rep Power
    31
    I finally ended up doing this ( stripped_title is this {title:re(^(A|The|An| or)\s+,)||} )

    {#stripped_title:re((\s|'|\\,|\/|\:|\!|\&|\.|),)||}

    I hate doing it that way. I'd rather take the title and have ONLY the letters and numbers remaining (for filename). This, however, does work and I'm keeping my eye on any new books I add to make sure I haven't missed anything that needs to be added to the replace.

    Now
    Generation 18
    becomes
    Generation18
    and
    Hob's Bargain
    becomes
    HobsBargain
    and
    Hello, Gorgeous!
    becomes
    HelloGorgeous

    It's not ideal, but it is working.

    HeadElf
    HeadElf
    OfficeElf.com
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,958
    Rep Power
    9397
    I don't know what syntax you'd use to replace stuff (though I think you figured it out) but the search pattern should look like
    Code:
    [^a-z0-9]
    So taking a guess,
    Code:
    {#stripped_title:re([^a-z0-9])||}
    If it's case-sensitive then you'll need a A-Z in there too.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    395
    Rep Power
    31
    and I get TEMPLATE ERROR Incorrect number of arguments for function re. It works if I add a comma after the right parenthesis.

    Thanks.
    HeadElf
    OfficeElf.com

IMN logo majestic logo threadwatch logo seochat tools logo