Repeating character help

  • Dion

    Dion - 2011-11-25

    Hi all,
    I'm trying to write a little script to replace and standardize all the different ways of writing an hellipses ("…"). Some people put spaces before, or after, or both - some put spaces between the periods - some use 3 dots while others use 4.

    I am currently stuck with the following code - but it seems clunky, inelligant, slow, and still doesn't catch everything:

    editor.replace(r" . . . .", r"…")
    editor.replace(r". . . . ", r"…")
    editor.replace(r". . . .", r"…")
    editor.replace(r" . . . ", r"…")
    editor.replace(r" . . .", r"…")
    editor.replace(r". . . ", r"…")
    editor.replace(r". . .", r"…")
    editor.pyreplace(r"*…*", r"…")
    editor.pyreplace(r"*…*", r"…")

    What I would LIKE to use is something along the lines of:

    editor.pyreplace(r"*(\.*){2,}", r"…")

    this should catch:
    0 or more leading spaces
    2 or more (period followed by 0 or more spaces)

    but that doesn't seem to work.  I also tried a "+" instead of the "{2,}" but that found all of the periods at the end of sentences.

    Does anyone have an idea of how I can do this??


  • Dion

    Dion - 2011-11-25

    OK - I really wish there was a way to delete your own post…..That way I wouldn't look like such an idiot by asking the above question !!!  lol

    The line: 
    editor.pyreplace(r"*(\.*){2,}", r"…")  

    DOES work…you just have to remember to test it using the python CONSOLE and not by pasting the REGEX into the built in replace function…..duh



Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks