I need to find the lines which is having three ; in notepad ++



  • Hi

    i have text as below in notepad ++ i want to mark the row which is having three ;(semicolons)

    aksdjfkl;asdjfllkfj;sjdfljk;asdjfhk;;

    2344;kdsfjl;;

    ";1233;;

    ksdjfl;kdjfl;sj22jdj;

    jdsfhlkskdjf;kjjdhfkj;jdkfhsd;;

    i want to mark the below rows with regular expression

    2344;kdsfjl;;

    ";1233;;

    ksdjfl;kdjfl;sj22jdj;

    Thanks.



  • @Bhogesh-WaraPrasad ,

    That doesn’t seem like a difficult regex to develop. I am curious that you didn’t at least try something.

    • FIND = ^[^;\r\n]*?;[^;\r\n]*?;[^;\r\n]*?;[^;\r\n]*?$

    Explanation: start of line, look for 0 or more of anything but semicolon or newline, followed by exactly one semicolon; repeat that a total of three times, then match 0 or more of anything but semicolon or newline again, until the end of the line.

    Using fancy syntax, that could be simplified, but it’s not necessary to make it work:
    For example,

    • ^(([^;\r\n]*?);){3}(?2)$ creates a group 1 which contains group 2 plus a semicolon; group 2 looks for 0 or more chars that are not a semicolon or newline; group 1 is repeated three times, followed by one more match against group 2’s rules

    There are other ways, too
    ----

    Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the </> toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipbpard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.



  • @PeterJones said in I need to find the lines which is having three ; in notepad ++:

    ^(([^;\r\n]*?);){3}(?2)$

    Thank you PeterJones for you help, it is working fine

    I have tried in many ways, because of urgency i have posted in community

    \R(?=")
    \R(?=abcdefghijklmnopqrstuvwxyz)
    \R(^?=1234567890)
    find ^([^;;][;;]?[^;;]){0,2}$
    \R(?=[a-z"1)2) ])
    \R(?=[a-z".,#])



  • @Bhogesh-WaraPrasad ,

    For future reference, when asking for help – which is perfectly fine – it’s usually best to show what you tried already and why you thought it might work: that gives the people helping you a place to start. Sometimes, they end up rejecting that method altogether, but at least they know that you aren’t just asking them to do your homework, and might have an idea of what regex concepts you already know, so they can craft their answer to help address your specific needs.

    edit: BTW: thank you for giving examples of what should and what should not match. that helped me craft my initial response so we got first-attempt success, rather than having to go back and forth a bunch. Originally, I thought you meant “at least three semicolons”, but your test data showed me you wanted “exactly three semicolons”. So thank you. /edit



  • Hello, @bhogesh-waraprasad, @peterjones, @alan-kilborn and All,

    From this discussion, after some tests, here is an other generic regex which selects all the contents of all lines containing, exactly, N to M times, the Char character, per line :

    ^([^Char\r\n]*)(Char(?1)){N,M}$    or    ^([^Char\r\n]*)(Char(?1)){N}\R if you want to match their line-breaks, too

    So, you can, either, mark, delete or replace these lines ;-))


    Notes :

    • Char represents a single character, which is, usually, a non-word character ( A punctuation or symbol char )

    • N and M must be replaced with the appropriate integers ( For instance {2,4}, {5,}, {0,3}, {2} or even {0} )

    • So the search regex OP is ^([^;\r\n]*)(;(?1)){3}$

    Best Regards,

    guy038


Log in to reply