Copy link to clipboard
Copied
Hello, struggling to get my head round an expression that will do this... need to add a bold style to a couple of variations on a few words always after a 'the' for example:
take a look at the dolphin ecolocation visual
watch the dolphin hunting video
look at the dolphin ecolocation handout
I've bolded what I want to bold within the text. I've tried a few variations on positive look aheads and using an or expression to cover the various endings of the phrase i'm looking for... rough outline of where I got to below
(?=the)\w+((?i)video|(?i)visual)
Add (?s) at the begining.
(?s)(?<=the ).+?(visual|video|handout)
Copy link to clipboard
Copied
Try this one. You were missing a space after the initial "the" and \w don't match space between words so it's better to replace it with a dot "any character". If you have use the (?i) because this could be in upper and lower case you can put it at the begining of the query.
(?=the ).+?(visual|video|handout)
Copy link to clipboard
Copied
This is bolding the 'the' as well which I don't want...
Copy link to clipboard
Copied
Copy/Paste error... misisng <
(?<=the ).+?(visual|video|handout)
Copy link to clipboard
Copied
Hi Jean-Claude, is there a way to take into account for soft returns? I tried using \s but i'm not sure it's classed as a white space character.
Copy link to clipboard
Copied
\n is a soft return character.
(?<=the )(.|\n)+?(visual|video|handout)
Copy link to clipboard
Copied
Add (?s) at the begining.
(?s)(?<=the ).+?(visual|video|handout)
Copy link to clipboard
Copied
I'm concerned that you're not providing enough context as to how your sample text will appear in the bigger picture. That being said, I've included a screen shot below of the GREP expressions that I wrote to make this happen. I'm basically just using a positive lookbehind for "take a look at the", "watch the", and "look at the", and then applying bold to everything that follows it.
Copy link to clipboard
Copied
Hi Chad,
the sample text was just an example, the text before what I want will be hard to predict but I know that follwing a 'the' and up to visual/handout/ etc is consistent
Copy link to clipboard
Copied
In that case, Jean-Claude's expression should work. Did you try it?
Copy link to clipboard
Copied
I would also use @Jean-Claude Tremblay's grep, maybe modified a bit to get better performance:
(?s)(?<=the ).+?(handout|vi(deo|sual))
Copy link to clipboard
Copied
Well, if it's performance you're after you should use non-matching subexpressions and \K instead of the classic lookbehind:
(?s)the \K.+?(?:handout|vi(?:deo|sual))
P/