Parenthetical Issue

Results 1 to 2 of 2

Thread: Parenthetical Issue

  1. #1
    Join Date
    Dec 1969

    Default Parenthetical Issue

    Let me preface this by saying I&#039;m somewhat of a RegEx neophyte despite using them off and on for months now. I guess I haven&#039;t quite fully latched on to all the formatting caveats. So be gentle. :)<BR><BR>That said.<BR><BR>I have a sample two-line text string:<BR><BR>(cat dog) (cow) some random text<BR>(bird) more random text<BR><BR>The RegEx pattern I want to come up with will match everything within the FIRST set of parentheses on each line only. So the matches I want to get are: (cat dog) from the first line and (bird) from the second.<BR><BR>Given that the text I&#039;m working with can have any number of words within that first set of parenthesis, I&#039;m getting stumped on how to select the entire first parenthesis set without getting any subsequent parenthesis sets on the same line of text.<BR><BR>I tried the simple approach:<BR><BR>.*)<BR><BR>But that matches (cat dog) (cow) as one match rather than just (cat dog).<BR><BR>I&#039;ve tried a myriad of patterns using w+ and trying to match just one open-parenthesis but they mostly result in no matches at all.<BR><BR>Help? :)

  2. #2
    Join Date
    Dec 1969

    Default here you go

    ^(([^)]+))<BR><BR>the first ^ means the start of the line. The character class [^)] means any character except a )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts