-2

Am working in Indesign. The idea is that a student can choose what word makes the sentence correct. Want to use grep or nested styles to acchieve the following:

So i have a series of sentences where i want to have the latest word before a slash and the first word after the slash to be styled.

Example: This man makes / does an appointment

How can i use grep to style the words (makes and does) around the / (back slash) and make them bold.

  • How to only select a word?
  • I could try to find two spaces before and after the / forward slash

code i tried and got all my words before the slash in same style: ^.*?(/|$)

Hope you can help me out

1 Answers1

1

There are several ways to match a word – and it mainly depends on what you call a "word". If it's anything not-whitespace, then you can use \S+. This will include ounctuation such as parentheses, apostrophes, comma's and full stops as well.
If it is a sequence of "word characters" (letters, digits, and, for historical reasons, the underscore), use \w+.
Any other custom sequence is possible as well with a custom character selection: [-A-Za-z]+, for example, will only include capital and lowercase latin characters and the hyphen.

For your purpose, you can use either of the above. It does not specifically need a lookbehind and lookahead. To match "word / word" all you need is \w+ / \w+; then apply a no-bold style (if there is a visible difference in that '/' alone) to just /.

But of course it can be done with both a lookahead and a lookbehind as well: \w+(?= /)|(?<=/ )\w+ should work nicely:

that GREP style at work on some example text

Jongware
  • 22,200
  • 8
  • 54
  • 100