[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

regular expression

Johnathan Smith

1/14/2008 1:08:00 PM

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
--
Posted via http://www.ruby-....

13 Answers

Robert Klemme

1/14/2008 1:19:00 PM

0

2008/1/14, Johnathan Smith <stu_09@hotmail.com>:
> 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

--
use.inject do |as, often| as.you_can - without end

Johnathan Smith

1/14/2008 1:43:00 PM

0

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
--
Posted via http://www.ruby-....

Robert Klemme

1/14/2008 1:47:00 PM

0

2008/1/14, Johnathan Smith <stu_09@hotmail.com>:
> 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?

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... :-)

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end

Johnathan Smith

1/14/2008 1:59:00 PM

0

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
--
Posted via http://www.ruby-....

Robert Klemme

1/14/2008 2:06:00 PM

0

2008/1/14, Johnathan Smith <stu_09@hotmail.com>:
> 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?

Yes.

robert

--
use.inject do |as, often| as.you_can - without end

Johnathan Smith

1/14/2008 2:10:00 PM

0

thank you.

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

thanks
--
Posted via http://www.ruby-....

Rick DeNatale

1/14/2008 2:14:00 PM

0

On 1/14/08, Johnathan Smith <stu_09@hotmail.com> wrote:
> 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?

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


--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Johnathan Smith

1/14/2008 2:25:00 PM

0

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
--
Posted via http://www.ruby-....

Moises Trovo

1/14/2008 3:01:00 PM

0

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.

On Jan 14, 2008 11:24 AM, Johnathan Smith <stu_09@hotmail.com> wrote:
> 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
> --
> Posted via http://www.ruby-....
>
>

Robert Klemme

1/14/2008 3:33:00 PM

0

2008/1/14, Johnathan Smith <stu_09@hotmail.com>:
> 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

--
use.inject do |as, often| as.you_can - without end