Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #25938

    tuska
    Participant

    http://www.emeditor.org/en/faq_search_search_multi-string_line.html
    On the right side of the Find drop-down list box, click the > button to display a menu, and select the Multiline.
    Moreover, drag the right bottom corner of the dialog box so the text box allows multiple lines.
    In order to enter a new line, use CTRL + ENTER.

    Hi,

    I have already made some searches, e.g.
    – Ctrl + Shift + F: Find in Files
    – Ctrl + H: Replace
    with
    – (None)
    – with/without Regular Expressions
    – Escape Sequence
    but without success.

    Example:
    1
    2
    3
    09
    4
    5

    I want to find 2 and 4 (should be marked then).
    In the search field I entered 2 Ctrl+ENTER and then 4 Ctrl+ENTER.
    The cursor was placed at the beginning of the file and then the button “Find Next” was pressed.

    As a result I get the following message in the status bar:
    “Cannot find 24 below the current position.”

    For me it looks like Ctrl+ENTER has no effect on multiline.
    A single digit can easily be found.

    I therefore ask for support or a step-by-step guide, how to solve this issue.
    I have only beginner’s knowledge…

    Windows 10 Pro (x64) Version 1903 (OS Build 18362.207)
    EmEditor Professional (64-bit) Version 18.9.12

    Regards,
    Karl

    #25939

    Patrick C
    Participant

    I’m really short on time and its not the complete answer, but the regex for finding 2 or 4 is:
    [24]

    This will however, select only one of the characters at a time.

    #25940

    tuska
    Participant

    2Patrick C
    Thank you for your solution.

    On my PC the following is marked in EmEditor (in a .txt file):

    2
    4
    24

    and I am very happy with that (because it is the first time that anything is marked at all).

    How I can find e.g. with RegEx
    – exact number 2 and 4
    – the number 2 and 09
    I have to learn first (RegEx).

    Thanks again.

    Regards,
    Karl

    #25941

    tuska
    Participant

    However, I still don’t know what a solution without RegEx knowledge looks like,
    i.e. for which example CTRL + ENTER is to be used.

    Please support me on this question.

    #25942

    tuska
    Participant

    Here is a picture:
    Multiple-line CTRL-ENTER Find-Replace

    #25947

    LTT
    Participant

    Ctrl+Enter (in Multi-line mode) = \n (in Single-line mode).

    If you want to search for a multi-line string, usually you have to match the exact number of the lines:

    2\n.*\n4 matches:
    2
    anything
    4

    2\n.*\n.*\n4 matches:
    2
    anything
    anything
    4

    All in this post are Regular Expressions:
    http://www.emeditor.org/en/howto_search_search_regexp_syntax.html

    And note that EmEditor cannot highlight multi-line matches with colors.

    —————
    If the number of lines is uncertain, open “Advanced…”:

    Additional Lines to Search for Regular Expressions:
    Enter a number (the maximum for your case).
    [★The help for this option is important.]
    (Don’t forget that in such dialog boxes you can press F1 for help.)

    ** But currently you have to relaunch EmEditor to make the change effective. (It could be a bug.)

    Expression 1:
    2[\s\S]*4 should now work for you.

    Expression 2:
    Open “Advanced…”:
    Enable: Regular Expressions “.” Can Match Newline Characters.
    2.*4 should also work now.

    —————
    While “Find in Files” is different:
    (It doesn’t need “Additional Lines to Search for Regular Expressions”.)

    2[\s\S]*4 always works.

    2.*4 works only if you enable the option:
    Regular Expressions “.” Can Match Newline Characters.
    [★The help for this option is important.]

    I have to say the design for such multi-line searches in EmEditor is complicated and inconvenient…

    #25950

    tuska
    Participant

    2LTT
    Thank you very much for your examples with RegEx and efforts to bring the topic closer to me.
    Unfortunately, I’m afraid I’m more confused now than before.

    Ctrl+Enter (in Multi-line mode) = \n (in Single-line mode).

    If I do CTRL + ENTER as in the picture above, I won’t get any results with the following options:
    ☑ Multiline
    ◉ (None)
    ◉ Regular Expressions
    ◉ Escape Sequence

    Is this a bug of EmEditor or an application error of mine?
    Are multi-line queries only allowed with the option ◉ Regular Expressions?

    If you want to search for a multi-line string, usually you have to match the exact number of the lines:

    Does this mean that I have to go to the end of each text document before searching to determine the exact number of lines?

    And note that EmEditor cannot highlight multi-line matches with colors.

    Mmmh, with
    ☑ Multiline
    ◉ Regular Expressions
    (^2$|^4$)
    in a .txt file the numbers 2 and 4 are marked in green.

    In the example in the picture I wanted to find exactly the numbers 2 and 4 in a range from 1 to 5, with or without RegEx.
    To complicate matters, I would also like to add the number 24 to the list and this number should not be marked.
    Unfortunately, I do not know how it would be possible to make an exact definition, so that only numbers 2 and 4 would be marked.

    Perhaps it would be possible if you or someone else could answer these questions for me.

    #25951

    tuska
    Participant

    If you want to search for a multi-line string, usually you have to match the exact number of the lines:
    Does this mean that I have to go to the end of each text document before searching to determine the exact number of lines?

    And note that EmEditor cannot highlight multi-line matches with colors.
    Mmmh, with
    ☑ Multiline
    ◉ Regular Expressions
    (^2$|^4$)
    in a .txt file the numbers 2 and 4 are marked in green.

    Please regard this text as irrelevant.
    That was a misunderstanding on my part.

    For me, there are currently only two questions left unanswered:
    – CTRL + ENTER (see previous post)
    Exact search for a number with RegEx, e.g. find 2 and 4 in a range from 1,2,3,4,5,24 (see previous post).

    #25952

    Patrick C
    Participant

    Welcome to the regex kitchen stew (semi serious; regex seems to drive most people I know either mad or desperate or both)

    Anyway one possible RegEx for finding 2 or 4 but not 24 is:
    (2(?!4)|(?<!2)4)

    Which works on
    1
    2
    3
    09
    4
    5
    24
    51
    1,2,3,09,4,5,24,51,4,2,42,8,4,6,2,8
    2
    4

    To get an idea on what this does
    (a|b)
    finds either a or b, where
    a = 2(?!4) finds 2 without a trailing 4
    b = (?<!2)4 finds 4 without a leading 2

    Note that I’m not a regex guru.

    #25953

    Patrick C
    Participant

    Tip: My preferred tool for testing out and learning regex is
    regex101 dot com

    #25954

    tuska
    Participant

    2Patrick C
    Thank you for your code, which is the solution for my example above.
    Your example also finds the number 42 – this should not be found.

    I don’t know if there is a solution:
    Only 2 and 4 should be found, i.e. exactly:2 and exactly:4.

    If there are any combinations in which the numbers 2 and 4 are contained,
    such as 1024, 42, 4242, 1524, 2415, 124215, 754224, etc., then the numbers should not be found/marked.

    regex101 dot com is also my favorite site because it offers explanations – but I am a complete beginner…

    #25955

    Mr KT
    Participant

    Hi Tuska,
    try this (just with regular expressions radio button on):

    (?<![0-9])[24](?![0-9])

    Explanation:
    (?<![0-9]) means negative look-behind, check no number before 2 or 4
    [24] means find 2 or 4
    (?![0-9]) means negative look-ahead, check no number after 2 or 4

    #25956

    tuska
    Participant

    Hi Mr KT,
    (?<![0-9])[24](?![0-9])
    works perfectly!
    Thank you very much.

    #25957

    tuska
    Participant

    For me, there is currently only one question left unanswered: CTRL+ENTER (in Multi-line mode) – (see previous post):
    If I do CTRL + ENTER as in the picture above, I won’t get any results with the following options:
    ☑ Multiline
    ◉ (None)
    ◉ Regular Expressions
    ◉ Escape Sequence
    Is this a bug of EmEditor or an application error of mine?
    Are multi-line queries only allowed with the option ◉ Regular Expressions?

    #25958

    LTT
    Participant

    So it turned out you were not really searching for multip-line strings…

    No need to use that Multiline mode unless you want to match a multi-line string.

    That box in Multiline mode is not a “list”, if you thought it was.

    If the above is enough to answer the last question, don’t read further in case you will be confused again. ;)

    ——————————
    As for Multiline mode with search options:

    If you turn on “Multiline” with “(None)”, only exact-text searches can be done.
    e.g. in Find box:
    2
    3
    4
    only matches as a whole:
    2
    3
    4

    However, EmEditor does such a search using “Escape Sequence” internally.
    The expression is saved as “2\n3\n4”. And if you turn off “Multiline”, “Escape Sequence” will be turned on automatically.

    So, to search for a multi-line string,
    either you always use Multiline mode with “(None)” to do an exact-text search,
    or, turn on “Escape Sequence” at least and use “\n”.

    Escape Sequence syntax is very simple. See it in the menu of the “>” button.
    A common text search only needs \n \t \\ when necessary.

    Use Regular Expressions if the content/length of the matches is uncertain.

    ——————————
    >… are marked in green.

    EmEditor cannot highlight multi-line matches with colors.
    A match will be highlighted with colors unless it’s multi-line.

Viewing 15 posts - 1 through 15 (of 25 total)

You must be logged in to reply to this topic.