Either find or skip comma(s) inside parentheses



  • Hi all,
    I need a regex that will find or skip comma(s) inside parentheses in a line - skipping is preferred.
    Searched and found a few for square brackets but, to my surprise, I can’t adjust them to parentheses: (?:[|(?!^)\G)[^,]]*\K,

    Ex:
    It should find the comma(s) in “(settlement, bargain, audit, cash)” and “(prompt, name, settling, ticket)” and skip the one in “day (time) of reckoning, (Börse) account” or the other way around, find the one in “day (time) of reckoning, (Börse) account” and skip the ones in parentheses: “settling (settlement, bargain, audit, cash) day, day of account, day (time) of reckoning, (Börse) account (prompt, name, settling, ticket) day (Br.),”

    Thanks in advance!
    glossar



  • @glossar said in Either find or skip comma(s) inside parentheses:

    It should find the comma(s) in “(settlement, bargain, audit, cash)” and “(prompt, name, settling, ticket)” and skip the one in “day (time) of reckoning, (Börse)

    Your question is a bit vague. You don’t care which way, find or skip yet the method to do so would vary greatly. Since your Ex: suggested find within the parentheses that’s what I’ve done.
    Find What:(\(|\G)[^\),]*\K,

    Not sure where you intend going with this since you have an end goal in mind but haven’t provided that, not that it necessarily needs to be provided for a “Find” to work. It does sometimes help in getting the full story so we might be able to provide a different idea that works better.

    Sorry had to edit as was using the squares originally when attempting to decipher your regex.

    Good luck
    Terry



  • @Terry-R said in Either find or skip comma(s) inside parentheses:

    ((|\G)[^),]*\K,

    Thank you so much, it works! :)



  • Hello, @glossar, @terry-r and All,

    Some other regexes !

    • To match any non-empty single-line area, between ( and ) included, not containing any ,, use the regex

      • \([^(),\r\n]*\)
    • To match any non-empty single-line area, between ( and ) included, containing, at least, one ,, use the regex

      • (?-s)\([^(),\r\n]*,.+?\)
    • To match any non-empty single-line area, between ( and ) not included, not containing any ,, use the regex

      • \(\K[^(),\r\n]*(?=\))
    • To match any non-empty single-line area, between ( and ) not included, containing, at least, one ,, use the regex

      • (?-s)\(\K[^(),\r\n]*,.+?(?=\))

    Best regards,

    guy038


Log in to reply