Want to set an algorithm to search



  • Hello, I need to get a specific search result in text. I need to find lines where only certain numbers are greater than “x”. How can i made it? Sorry for my bad english, i hope you understand me



  • @Вадим-Белянский said:

    I need to find lines where only certain numbers are greater than “x”

    As a short answer, it is NOT possible. Regex (regular expressions) have no ability to look for “greater than” or “less than” an amount. So no mathematical ability.

    However there is a way around it depending on the number. In regex we can look for numbers that are x digits long, so if you are looking for a number greater than 999 we could say \d{4,} which means any number as long as it is 4 digits or more long.

    If you wanted to say look for something greater than 345, then it becomes very difficult. Firstly we’d be looking for 4 digits or more, then for any 3 digits long we’d need to have first digit being 4-9. Then below that we continue checking 2nd digit and 3rd digit. Hopefully you understand my meaning.

    So not impossible, just difficult.

    Terry



  • @Вадим-Белянский said:

    How can i made it?

    As an exercise that might help explain the method I outlined before.
    Say we are looking for numbers greater than 229. I have the following numbers as an example

    234
    229
    245
    1000
    199

    So the regex to mark these lines containing the numbers I want is:
    Find What:(\d{4,})|([2-9][3-9]\d)
    If you have “bookmark line” also ticked on the Mark function you will see it marks
    234
    245
    1000
    only

    This is only a simple example, the longer the number of characters the more complicated the regex becomes. Whilst it will work it is NOT the most efficient method. In english it can be likened to hitting a pin with a sledgehammer to push it in.

    Terry


Log in to reply