Skip to main content
Known Participant
June 26, 2022
Answered

Questions about Greps and FindChangeByList

  • June 26, 2022
  • 1 reply
  • 710 views

I'm willing to write a grep code to find my desired words. I'm looking for the word X that there are one or more kinds of spaces before it, or the word X is at the beginning of a paragraph. So far, I wrote this grep code:

([~|~< ]{1,}X)


The problem is I cannot add the ^ --that indicates the beginning of a paragraph to my grep code.
Since I'm writing a grep code, so I cannot add the WholeWord scope to my search, therefore, I wrote {1,} in my code.

This topic has been closed for replies.
Correct answer m1b

In that case you should be able to use either

\<X\>

or

\bX\b

- Mark 

1 reply

m1b
Community Expert
Community Expert
June 26, 2022

Hi @SunFlower16, if you are using Find Grep (not ExtendScript) you can use something like

^\s*\K\w+

to find the first word in a paragraph, even if there are spaces before it. Or a specific word "Word":

^\s*\KWord

- Mark

Known Participant
June 26, 2022

Thanks dear Mark.
Your grep code works properly, but it only has one part of my desired function. I'm willing to find the word X whether it is at the beginning of the paragraph or in the middle of a text. Let me clarify

X is a sample sentence.
is X a sample sentence.

 In both above sentences, I want to find the word X. Your grep code however only finds the X in the first sentence, not the second sentence.

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
June 26, 2022

In that case you should be able to use either

\<X\>

or

\bX\b

- Mark