Skip navigation
Currently Being Moderated

Grep style: x words, maybe with punctuation

Feb 8, 2013 12:21 PM

I'm looking for a way to apply a character style when there's a dash within the first 6 words of the beginning of a paragraph. I've gotten this far:

 

^\w+(\s\w+){0,5}~_

 

But it fails if there is any punctuation before the dash. This is for formatting datelines, so there will be commas and periods and hyphens. How can I count words in this messy language of ours?

 
Replies
  • Currently Being Moderated
    Feb 8, 2013 1:07 PM   in reply to RobertKyle

    Don't do a GREP style. You merely need a nested paragraph style that says apply a certain character style UP TO or THROUGH the em dash.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 1:53 PM   in reply to RobertKyle

    Is there a compelling reason not to use two paragraph styles? Presumably it's the first graph in a story (or the one after the byline, or wahtever -- some predictable position) that carries the dateline and you could use "next style" to switch into, possibly, and out of the Dateline style.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 11, 2013 1:32 PM   in reply to RobertKyle

    With the use of the 'next style' in the definition, byline can be followed by dateline can be followed by story body and all they have to do is hit the enter key and type, or if you import the stories unformatted, select all, right click the byline style in the panel, and choose Apply Byline, Then Next Style.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 11, 2013 2:22 PM   in reply to RobertKyle

    If you datelines are consistant how they are set up, you could write a grep to match that. For instance: the grep below with style both datelines below, but leave the un-datelined text alone. (note the spaces in the code)

     

      ^.+ \(\d{1,2}/\d{1,2}/\d{1,2}\) —

    Screen shot 2013-02-11 at 5.18.22 PM.png

     

    The paragraph style with this GREP style included is applied to all three paragraphs, and functions properly. It find any text at the beginning of the paragraph, followed by the date format and the em dash.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 11, 2013 3:51 PM   in reply to RobertKyle

    \w indeed only picks up alphabetics and numerals. Since you are dealing not only with words, but actually with anything-except-space, separated by real spaces, you can use \S instead (which is, effectively, "not-a-space"):

     

    ^\S+(\s\S+){0,5}~_

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points