need help on regular expression pattern

  • Thread starter Thread starter yoni
  • Start date Start date
Y

yoni

Hi,
I am looking for a regular expression that will find something like
that
"Word.word"
But also:
"Word.*"

I came up with:
\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\.[?[A-Za-z_*][A-Za-z_0-9]*\]?\b

each 'word' begins with a letter and can have numbers after it, and
can have brackets. It all works, but fails when I want to find the 2nd
example, like 'something.*', (last word can be a * in addition to
just text) which is where I am stuck. I originally started with this:

\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\.[?[A-Za-z_][A-Za-z_0-9]*\]?\b

And then added the * there (the [A-Za-z_*] in:
\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\.[?[A-Za-z_*][A-Za-z_0-9]*\]?\b) as part
of the character class. WHY DOES IT NOT FIND IT? Thanks!
 
Hi,
I am looking for a regular expression that will find something like
that
"Word.word"
But also:
"Word.*"

I came up with:

\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\.[?[A-Za-z_*][A-Za-z_0-9]*\]?\b

did you forget about \ ?
\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\. >>>\<<< [?[A-Za-z_*][A-Za-z_0-9]*\]?\b
 
Thanks for your quick response. but that wasnt the issue. i managed to
narrow it down to this:
before, i needed to search for a word, so something like
\b[?[A-Za-z_][A-Za-z_0-9]*\b was fine. now, the word may end with a *.
i cannot do this:

\b[?[A-Za-z_*][A-Za-z_0-9]*\b

because \b is ONLY AFTER A WORD CHARACTER, which * is not. i still want
to find it as a 'whole word', meaning i need the \b at the end, so i
discovered i can do something like:

\b[?[A-Za-z_*][A-Za-z_0-9]*\W

ending with \W instead of \b. one problem is this doesnt work at the
end of a string, which \b did. any idea how to fix it? find a substring
that ends with an asterik, either at the end of a string buffer or
anywhere in the middle of it

thanks!!
Hi,
I am looking for a regular expression that will find something like
that
"Word.word"
But also:
"Word.*"

I came up with:

\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\.[?[A-Za-z_*][A-Za-z_0-9]*\]?\b

did you forget about \ ?
\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\. >>>\<<< [?[A-Za-z_*][A-Za-z_0-9]*\]?\b
 
Thanks for your quick response. but that wasnt the issue. i managed to
narrow it down to this:
before, i needed to search for a word, so something like
\b[?[A-Za-z_][A-Za-z_0-9]*\b was fine. now, the word may end with a *.
i cannot do this:

\b[?[A-Za-z_*][A-Za-z_0-9]*\b

because \b is ONLY AFTER A WORD CHARACTER, which * is not. i still want
to find it as a 'whole word', meaning i need the \b at the end, so i
discovered i can do something like:

\b[?[A-Za-z_*][A-Za-z_0-9]*\W

ending with \W instead of \b. one problem is this doesnt work at the
end of a string, which \b did. any idea how to fix it? find a substring

This should match whitespace or end-of-string:

(\W|$)
that ends with an asterik, either at the end of a string buffer or
anywhere in the middle of it

thanks!!
Hi,
I am looking for a regular expression that will find something like
that
"Word.word"
But also:
"Word.*"

I came up with:

\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\.[?[A-Za-z_*][A-Za-z_0-9]*\]?\b

did you forget about \ ?
\b\[?[A-Za-z_][A-Za-z_0-9]*\]?\. >>>\<<<
[?[A-Za-z_*][A-Za-z_0-9]*\]?\b
 
You need to spell out your rules more clearly. For example, you said that
"each 'word' begins with a letter and can have numbers after it, and can
have brackets." By that definition, you could mean any of the following:

A[]
[A123]
A123[456]
A{123}
{A}

The most important step to writing a good regular expression is to clearly
define the rules for the pattern.

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

Where there's a Will, there's a William.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top