Regular expression

hey

im lookiing to be able to write a regular expressions which deals with
10 letter strings which end in either “ed” or “ing”

any help would be much appreciated

thanks

2008/1/14, Johnathan S. [email protected]:

im lookiing to be able to write a regular expressions which deals with
10 letter strings which end in either “ed” or “ing”

any help would be much appreciated

Doesn’t sound too difficult. What did you came up with so far?

Kind regards

robert

hey

only a very basic start im afraid

^([a-zA-Z]{10})$

i.e
ten letter word (upper or lower case)
basically i need to get it now so it only deals with words with the
suffix’s a mentioned

any pointers?

thanks

2008/1/14, Johnathan S. [email protected]:

any pointers?

You can do either

if /^\w{7}(?:\wed|ing)$/i =~ str

process match

end

or

if str.length == 10 && /(?:ed|ing)$/i =~ str

process match

end

There are of course more alternatives… :slight_smile:

Kind regards

robert

i appreciate the help

however, im still having problems

im using the regex coach to see if i can get a match but im being
unsuccessful

im using

^\w{10}(?:\ed|ing)$

with the target string controlled

yet not getting a match
can you see why?

thanks

2008/1/14, Johnathan S. [email protected]:

with the target string controlled

yet not getting a match
can you see why?

Yes.

robert

thank you.

would be be able to offer any suggestions as to where im going wrong?

thanks

thank you.

what ive basically got now is

\w{7}(ed|ing)

was basically works for ing but only matches a 9 letter word for ed

there must be a better way to do it
ive been playing around to with no luck

any suggestions would be greatly appreciated

thanks

On 1/14/08, Johnathan S. [email protected] wrote:

with the target string controlled

yet not getting a match
can you see why?

That’s looking for 10 word characters FOLLOWED by either ed or ing.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

The “\w{7}” matches with 7 chars, so to match all your expression it
have to have 9 chars ending with ed and 10 chars ending with ing.

2008/1/14, Johnathan S. [email protected]:

thank you.

what ive basically got now is

\w{7}(ed|ing)

was basically works for ing but only matches a 9 letter word for ed

there must be a better way to do it
ive been playing around to with no luck

Maybe you should rather read what people write if they take the time
to help you.

any suggestions would be greatly appreciated

Have been made already.

Cheers

robert

On Mon, Jan 14, 2008 at 11:24:30PM +0900, Johnathan S. wrote:

thank you.

what ive basically got now is

\w{7}(ed|ing)

\w{7}(?:\wed|ing)

= 7 word characters followed by either a word character and the string
“ed” or the string “ing”.

was basically works for ing but only matches a 9 letter word for ed

Because your version tells it to match on 7 word characters followed by
“ed” or “ing”.

Dan

On Jan 14, 6:10 am, Johnathan S. [email protected] wrote:

thank you.

would be be able to offer any suggestions as to where im going wrong?

You didn’t copy/paste exactly what Robert wrote. You’re missing a
piece. Hint: \e is not meaningful in a (Ruby) regexp.

2008/1/15, Paul S. [email protected]:

You can also expand the alternation all the way through.
For instance, imagine: (?:\w{X}ed|\w{Y}ing)
for suitable numeric values of X and Y and applied anchoring.

But this is less efficient with NFA regexp engines because it has to
do more backtracking. Actually, I believe it is most efficient to
have the longest trailing portion first, e.g. /^\w{7}(?:ing|\wed)$/i.
If you are interested you can play a bit with
http://www.weitz.de/regex-coach/.

Kind regards

robert

You can also expand the alternation all the way through.
For instance, imagine: (?:\w{X}ed|\w{Y}ing)
for suitable numeric values of X and Y and applied anchoring.