Assistence With Using Asterisks in GREP Expressions

I am attempting to find all complete words which contain an asterisk at the beginning and the end - for instance, "*Hello?" or "*you".

From what I've read, I would have thought that the following expression would do that just fine:

\<\*.*\*\>

\< denoting the beginning of a word.

\* escaping the first asterisk

.* acting as a placeholder for any number of characters

\* escaping the second asterisk

and finally

\> to denote the end of the word.

Yet, the string doesn't do a thing. Why might that be? If it matters, I'm using this string in InDesign, but I figured here would be a better place to ask since it's technically a scripting issue. Might InDesign be using a pseudo-GREP structure, or is my script just wrong?

Thanks.

from what i know when were dealing with asterisk(*) char in a line we need to use double qoutes. This evaluates the "middle " (.) and use escape character on both the first character (^) and last character ($).

-bash-3.2$ cat test
*ryan*
*you
*me*
-bash-3.2$ cat test | grep "^\*.*\*$"
*ryan*
*me*
-bash-3.2$

Hop this is what you are looking for

sh-3.2$ cat f1
word1 word2 *word3* word4
word5 *word6*
*word7* word8* *word9*

sh-3.2$ grep -ow "*[^*]*\*" f1
*word3*
*word6*
*word7*
*word9*
sh-3.2$

you did not include last char check

-bash-3.2$ cat test
*wor*d1*
*wor*d
-bash-3.2$ grep -ow "*[^*]*\*" test
-bash-3.2$

I tried both - neither worked.

\<.*\> returns everything, as would be expected.

\<\*.*\> , however, doesn't return words that start with an asterisk. I think it's choking on asterisks for some reason. It doesn't make a difference if instead of escaping the asterisk, I put it in single or double quotes, like so:

\<'*'.*\>

\<"*".*\>

Can an asterisk not be legitimately part of a "word" - as defined by GREP? I figured a word was simply any string with spaces or tabs around it.

what do you mean not working? why do you use "\<"*".*\>"?

^ - denotes first char of the string
$ - last char of the string

my sample above came from my bash shell.

Simply that - your sample code does not return any results.

InDesign seems to store paragraphs as strings - as such I want to find words within that string that begin and end with an asterisk. For that, I believe the proper syntax is \< and \>

can you post your sample strings? and your testing?

Sure thing. I used screenshots because it seemed the easiest way to illustrate what's going on.

Here is the original text, with a GREP string of nothing.

I first tried a basic command - Italics on the string "you":


That worked fine.

I then attempted to put italics on every word:


That worked as well.

My next attempt was to put italics on every word that began with * and ended with *:


That one failed.

Thinking perhaps the problem might be with the "word" syntax (\< and \>), I tried simply checking for a space, an asterisk, any string, another asterisk, and another space:


This almost worked, but for some reason "How about" is italicized.

Hope that helps.

try enter this string

"^\*.*\*$"

I did - here's the result:

Wouldn't that look for whole lines that begin and end with asterisks, rather than individual words?

yeah it seems so

\<.*\>

your code seems to have an effect to the entire paragraph. I am now not sure if you can remove them.

Found it.

Apparently, punctuation isn't treated as part of a word, so it threw off the \< and \> tags. Instead, I've done this:

(\*)(\w+)[[:punct:]]*(\*)

asterisk, one or more words, possible punctuation marks, and a final asterisk.

Thanks for the help.