Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
tricky 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
  5 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
 
del  
View profile  
 More options Nov 1, 3:39 pm
From: del <d...@hotmail.com>
Date: Sun, 1 Nov 2009 12:39:43 -0800 (PST)
Local: Sun, Nov 1 2009 3:39 pm
Subject: tricky question
Hi, does anyone know how to do this? I’ve been banging my head on this
one all day (I’m not very good at this):

I am looking for a pattern to find all groups of digits separated by
blanks but not including the last blanks, e.g.

‘blah blah 12 dsa 12  43 999  etc.’ (should be in fixed size font)
           ^^     ^^^^^^^^^^                   (only numbers and
spaces in between)

I thought of using p=’(\d+\s*?)+’ but this finds individual numbers,
not groups (why?).
I tried p=’(\d+\s+?)+’ which finds the groups alright but retains 1
space at the end.
I tried ½ dozen other combinations including some with atomic groups
(e.g. \d++) without success.

Stumped.
Thanks ahead of time for any reply.
/Dan


    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 Nov 2, 1:25 pm
From: "Eugeny.Satt...@gmail.com" <eugeny.satt...@gmail.com>
Date: Mon, 2 Nov 2009 10:25:09 -0800 (PST)
Local: Mon, Nov 2 2009 1:25 pm
Subject: Re: tricky question
\b\d+\b(?!\x20*[\r\n]+)
will catch  all number sequences except the one that is followed by
optional space(s) and obligatory linebreak

Is this what you wanted?


    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.
del  
View profile  
 More options Nov 2, 1:52 pm
From: del <d...@hotmail.com>
Date: Mon, 2 Nov 2009 10:52:14 -0800 (PST)
Local: Mon, Nov 2 2009 1:52 pm
Subject: Re: tricky question
No. I don't quite understand the pattern but when I run it on the
example I gave it matches the numbers (groups of digits) only.
This seems to be like '\b\d+\b' to me.
I DO want the spaces between numbers but not the ones before or
after.

I don't understand why '(\d+\s*?)+' does not work, seems it should
(but what do I know?)

On 2 Nov, 18:25, "Eugeny.Satt...@gmail.com" <eugeny.satt...@gmail.com>
wrote:


    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 Nov 3, 2:06 am
From: "Eugeny.Satt...@gmail.com" <eugeny.satt...@gmail.com>
Date: Mon, 2 Nov 2009 23:06:27 -0800 (PST)
Local: Tues, Nov 3 2009 2:06 am
Subject: Re: tricky question
Looks like i found a solution.

my regex finds "12" and "12  43 999" in your target string
‘blah blah 12 dsa 12  43 999  etc.’ (should be in fixed size font)
           ^^     ^^^^^^^^^^

The regex below

\b\d(?(?=\x20*\d).)*\b

uses the power of if-then-else conditional construct. (Without "else"
branch here)
The regex acts as follows. Having found the first digit in a series of
digits (\b guarantees that it is the first) it checks what it has to
the right of the current position. If it is
1. a space or spaces or no spaces at all \x20*
followed by
2. a digit \d

then it includes the symbol to the right into the whole match.
The star ensures that this check&inclusion will be repeated cyclically
as many times as possible, but zero times is OK as well (it is a
nature of a star).

Note that the \d located before the first opening round bracket will
catch single digits, anyway.

Excerpt from PowerGREP regex tutorial:
=====================================

A special construct (?ifthen|else) allows you to create conditional
regular expressions. If the if part evaluates to true, then the regex
engine will attempt to match the then part. Otherwise, the else part
is attempted instead. The syntax consists of a pair of round brackets.
The opening bracket must be followed by a question mark, immediately
followed by the if part, immediately followed by the then part. This
part can be followed by a vertical bar and the else part. You may omit
the else part, and the vertical bar with it.

For the if part, you can use the lookahead and lookbehind constructs.
Using positive lookahead, the syntax becomes (?(?=regex)then|else).
Because the lookahead has its own parentheses, the if and then parts
are clearly separated.

--
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.
Затлер Евгений Викторович  
View profile  
 More options Nov 3, 3:59 am
From: Затлер Евгений Викторович <eugenysatt...@gmail.com>
Date: Tue, 3 Nov 2009 12:59:20 +0400
Local: Tues, Nov 3 2009 3:59 am
Subject: Re: tricky question

> I don't understand why '(\d+\s*?)+' does not work, seems it should

Because * is greedy, *? is lazy.

Lazy means "it is better to match nothing at all , than try to match anything"

The whole your expression matches OK without trying to match \s*? part.
"So why bother?"  - thinks regex processor...


    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