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

···

--
Posted via http://www.ruby-forum.com/.

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

Kind regards

robert

···

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

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

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-forum.com/.

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

···

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?

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

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-forum.com/.

Yes.

robert

···

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?

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

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

···

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?

--
Rick DeNatale

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

thank you.

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

thanks

···

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

any suggestions would be greatly appreciated

thanks

···

--
Posted via http://www.ruby-forum.com/.

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 Mon, Jan 14, 2008 at 11:24:30PM +0900, Johnathan Smith wrote:

--
Daniel Bye
                                                                     _
                                              ASCII ribbon campaign ( )
                                         - against HTML, vCards and X
                                - proprietary attachments in e-mail / \

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-forum.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

···

2008/1/14, Johnathan Smith <stu_09@hotmail.com>:

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

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

···

On Jan 14, 6:10 am, Johnathan Smith <stu...@hotmail.com> wrote:

thank you.

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

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

···

2008/1/15, Paul Stickney <pstickne@gmail.com>:

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.

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