Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

a little help with GREP?

Tagged: , ,

Return to Member Forum

  • Author
    Posts
    • #71213
      Anonymous
      Inactive

      hello, im working on a law paper and have some problems with numbers.. to be more specific:

      what i have:
      “you can find something in § 15, 25, 26, 27, 28, 29, 55..”
      what i want to have:
      “you can find something in § 15, 25-29, 55..”
      or
      “we discussed this problem on pages 15, 16, 17”
      what i want to have:
      “we discussed this problem on pages 15-17” (or 15 to 17, doesnt really matter)

      of course, the numbers are different every time, the point is i need to find a set of numbers in range and change them to a simple separator..

      is anything like this even possible by using GREP? or a script?

      many thanks!

    • #71250
      Oleh Melnyk
      Member

      Hi,

      I’m not a great scripter, but here is my solution https://www.dropbox.com/s/f6ctvw1kl5povi9/Detect%20digit%20range.jsx?dl=0

      Script code is pretty dirty and requires a strong refactoring, but seems it works just as it should – check and let me know how it goes…

      If somebody have any suggestions of how to improve this script – feel free to contact me!

    • #71421
      Anonymous
      Inactive

      hello there,

      sorry for the late response..

      your script works great! it finds all the numbers i want and changes it to what i need, but..

      ..it changes numbers i dont want to be changed, f.e. 5,6 changes to 5-6 (i only need to put the separator between three numbers in range, not two..)

      is it fixable? can you change the script this way? (i tried and failed miserably :)

      anyway, good job, thank you for it and if my problem with two numbers in range doesnt have the solution, i can handle it ;)

      thanks again and be well!

    • #71431
      Oleh Melnyk
      Member

      I spent whole day, trying to figure out how to make this work and how to refactor the code.. I thought that my brain will blow up.. but I finally made it, and now I get satisfaction from this)))

      check updated version and let me know if it works for you https://www.dropbox.com/s/llzn9d6iq8ikiyo/Detect%20digit%20range%202.jsx?dl=0

    • #71453
      Anonymous
      Inactive

      you, sir, you deserve a medal! works perfectly and thanks for the alert, i promise i will never run the script twice :D

      you didnt have to spend so much time with it but Im very glad you did :)

      i looked at the script you made and its so complicated my brain almost blew up as well, incredible!

      once again, thanks a lot!

      i wish i had something to offer to help you with (im afraid i dont but you can try ;)

      take care!

    • #71455
      Oleh Melnyk
      Member

      haha)) I just added another “if” to check if ranges are already set, so script will not screw up now after multiple execution.. you may remove alert if they bother you)))

      upd: https://www.dropbox.com/s/llzn9d6iq8ikiyo/Detect%20digit%20range%202.jsx?dl=0

    • #71557
      Anonymous
      Inactive

      the alerts are fine, at least i know i used the script correctly :)

      have a one tasty beer on me, good man! :)

      take care

    • #71558
      Oleh Melnyk
      Member

      actually I have discovered a serious bug in previous version: if there is more than one string with ranges – script replace second and all other digit-strings with first formatted result, which is not good.. so I made another update:

      https://www.dropbox.com/s/f6ctvw1kl5povi9/Detect%20digit%20range.jsx?dl=0

      in this version:
      – script work correctly with more than one digit-string per document
      – it can now work with selection only, if nothing selected – it will process whole document
      – it use progress bar instead of alerts
      … and other small fixes

    • #71618
      Anonymous
      Inactive

      you really want to get the medal, dont you? :)
      to be honest i tried the script only on a small piece of work and it worked good, i havent finished the whole job yet..
      but thank you again for taking care of the script, i believe this time its absolutely perfect (unless you find other bug in it :)
      thanks and be well!

    • #71619
      Oleh Melnyk
      Member

      no, I don’t need medals, lol
      I just have found this script useful, and I want to include it to my other script, that will be more complex and do multiple [clever] find/change fixes, that’s why I’m searching for bugs and keep fixing them

Viewing 9 reply threads
  • You must be logged in to reply to this topic.
Forum Ads