Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
newbie question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
SpaceMarine  
View profile  
 More options Oct 29, 1:57 pm
From: SpaceMarine <spacemar...@mailinator.com>
Date: Thu, 29 Oct 2009 10:57:37 -0700 (PDT)
Local: Thurs, Oct 29 2009 1:57 pm
Subject: newbie question
hello,

i have a test regex that looks for one of two possible favorite
colors:

    red|blue

...no problem. now id like to include "Favorite color: " into the test
string, like so:

    Favorite color: blue

...how do i modify the original regex to include this static label?
ive tried /b but it didnt work out.

thanks!
sm


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugeny.Sattler@gmail.com  
View profile  
 More options Oct 30, 6:01 am
From: "Eugeny.Satt...@gmail.com" <eugeny.satt...@gmail.com>
Date: Fri, 30 Oct 2009 03:01:09 -0700 (PDT)
Local: Fri, Oct 30 2009 6:01 am
Subject: Re: newbie question

On Oct 29, 9:57 pm, SpaceMarine <spacemar...@mailinator.com> wrote:

> hello,

> i have a test regex that looks for one of two possible favorite
> colors:

>     red|blue

> ...no problem. now id like to include "Favorite color: " into the test
> string, like so:

>     Favorite color: blue

Favorite color\: (red|blue)

--
regards,
Eugeny


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
inhahe  
View profile  
 More options Oct 30, 6:20 am
From: inhahe <inh...@gmail.com>
Date: Fri, 30 Oct 2009 06:20:03 -0400
Local: Fri, Oct 30 2009 6:20 am
Subject: Re: newbie question

On Fri, Oct 30, 2009 at 6:01 AM, Eugeny.Satt...@gmail.com <

eugeny.satt...@gmail.com> wrote:
> Favorite color\: (red|blue)

do :'s really need to be escaped? that could explain why some regex i wrote
the other day wouldn't work

also.. one thing i don't get about | -- how does it know you're looking for
"red" or "blue" and not "re" + ("d" or "b") + "lue"?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugeny Sattler  
View profile  
 More options Oct 31, 11:57 am
From: Eugeny Sattler <eugeny.satt...@gmail.com>
Date: Sat, 31 Oct 2009 19:57:57 +0400
Local: Sat, Oct 31 2009 11:57 am
Subject: Re: newbie question

>> Favorite color\: (red|blue)

> do :'s really need to be escaped? that could explain why some regex i wrote
> the other day wouldn't work

Not necessary but you are safer when it is escaped.
There are situations when ":"  are a part of special meaning in regex
(for example non-capturing groups start from "(?:" and end with ")"
so, it is better to escape ":" when you want to match it as literal

> also.. one thing i don't get about | -- how does it know you're looking for
> "red" or "blue" and not "re" + ("d" or "b") + "lue"?

Thanks to round brackets! Here, the first option starts right after
opening round bracket and ends before a pipe, the second option starts
right after pipe and ends before closing round bracket.

For single letters or digits a character class syntax is more suitable.
If you want to match "a" or "b" or "c" use [abc] construct.
Although you won't be punished if you use (a|b|c) construct.

(a|b|c) construct was meant for words, not for single letters.

--
regards,        Eugeny


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
inhahe  
View profile  
 More options Oct 31, 12:03 pm
From: inhahe <inh...@gmail.com>
Date: Sat, 31 Oct 2009 12:03:46 -0400
Local: Sat, Oct 31 2009 12:03 pm
Subject: Re: newbie question

On Sat, Oct 31, 2009 at 11:57 AM, Eugeny Sattler
<eugeny.satt...@gmail.com>wrote:

> > also.. one thing i don't get about | -- how does it know you're looking
> for
> > "red" or "blue" and not "re" + ("d" or "b") + "lue"?
> Thanks to round brackets! Here, the first option starts right after
> opening round bracket and ends before a pipe, the second option starts
> right after pipe and ends before closing round bracket.

> For single letters or digits a character class syntax is more suitable.
> If you want to match "a" or "b" or "c" use [abc] construct.
> Although you won't be punished if you use (a|b|c) construct.

> (a|b|c) construct was meant for words, not for single letters.

But how greedy is the |?

i mean for example if i have a(.*?b)+?(?=hi|bye).blah|hi|green$ .. how is
that grouped?  where does the alternative before the "|hi" begin?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eugeny Sattler  
View profile  
 More options Oct 31, 12:37 pm
From: Eugeny Sattler <eugeny.satt...@gmail.com>
Date: Sat, 31 Oct 2009 20:37:31 +0400
Local: Sat, Oct 31 2009 12:37 pm
Subject: Re: newbie question

> But how greedy is the |?
> i mean for example if i have a(.*?b)+?(?=hi|bye).blah|hi|green$ .. how is
> that grouped?  where does the alternative before the "|hi" begin?

1) that syntax looks erroneous  to me because the pipe between "blah"
and "hi" and that between "hi" and "green" are not accompanied by
round brackets.
Ask you regex processor if it has the same opinion. :)

2) boundaries of lookahed construct can serve as boundaries of alternation.
so, no need to write
(?=(hi|bye))
while it is enough to write
(?=hi|bye)

just as you did in your example.
Just bear in mind that "(?=(hi|bye))" and "(?=hi|bye)" are treated the same.
The first option starts after "?=" and ends before pipe. The second
option starts after pipe and ends before closing round bracket.

My advice: stop thinking that regex engine first finds a pipe in your
espression and afterwards looks for ends of your alternate options to
the right and to the left (in a greedy or lazy way).
The regex engine processes regular expression always from left to
right, and if it did not encounter an opening round bracket, you have
lost your chance to tell it that you start an alternation.

--
regards,                     Eugeny


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SpaceMarine  
View profile  
 More options Nov 4, 1:51 pm
From: SpaceMarine <spacemar...@mailinator.com>
Date: Wed, 4 Nov 2009 10:51:33 -0800 (PST)
Local: Wed, Nov 4 2009 1:51 pm
Subject: Re: newbie question
thanks!

On Oct 30, 4:01 am, "Eugeny.Satt...@gmail.com"


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google