in reply to extract sentences with certain number of a character

You shouldn't match for any character (.) but for any non-r character ( [^r] ) between your wanted 'r'.

Added: Additionally you should use anchors in your regex, otherwise it will match any line, in which your regex can match 4 r, even if there are more r's in that line.

  • Comment on Re: extract sentences with certain number of a character

Replies are listed 'Best First'.
Re^2: extract sentences with certain number of a character
by olus (Curate) on Apr 27, 2008 at 10:03 UTC

    code:

    /^[^r]*r[^r]*r[^r]*r[^r]*r[^r]*$/