[URGENT] Incremental matches!

View: New views
8 Messages — Rating Filter:   Alert me  

[URGENT] Incremental matches!

by is_maximum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello
I have a string we call it position and this is in the form of '1.2.1.1'

consider the current position I have is "1.1.2.1.3"

I need to extract the following values:

1
1.1
1.1.2
1.1.2.1
1.1.2.1.3

or if position is "1.1.2"

I need:
1
1.1
1.1.2

is this possible by using Regex?

thanks
-- Regards
Mohammad Norouzi
Help each other to reach the future faster
Pixelshot Photoblog
Brainable Blog

RE: [URGENT] Incremental matches!

by Adrian Lynch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Are you using ColdFusion?

No need to use RegEx, it's a list so:

<cfoutput>
<cfloop list="#position#" index="i">
        #i#<br />
</cfloop>
</cfoutput>

Not a complete solution for you but you can see how to get at all the list
elements.

Adrian
Building a database of ColdFusion errors at http://cferror.org/

-----Original Message-----
From: is_maximum
Sent: 19 November 2008 13:14
To: regex
Subject: [URGENT] Incremental matches!


Hello
I have a string we call it position and this is in the form of '1.2.1.1'

consider the current position I have is "1.1.2.1.3"

I need to extract the following values:

1
1.1
1.1.2
1.1.2.1
1.1.2.1.3

or if position is "1.1.2"

I need:
1
1.1
1.1.2

is this possible by using Regex?

thanks


-----
--
Regards

Mohammad Norouzi


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1189
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21

RE: [URGENT] Incremental matches!

by is_maximum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Adrian Lynch wrote:
Are you using ColdFusion?

No need to use RegEx, it's a list so:

<cfoutput>
<cfloop list="#position#" index="i">
        #i#<br />
</cfloop>
</cfoutput>

Not a complete solution for you but you can see how to get at all the list
elements.
Thanks Adrian, No actually I am using Java Regex but I think they are alike. I want not to use any for loop

-- Regards
Mohammad Norouzi
Help each other to reach the future faster
Pixelshot Photoblog
Brainable Blog

Re: [URGENT] Incremental matches!

by S. Isaac Dealey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> consider the current position I have is "1.1.2.1.3"
>
> I need to extract the following values:
>
> 1
> 1.1
> 1.1.2
> 1.1.2.1
> 1.1.2.1.3

I don't think there's a way to get that with a single regex... But this
would work

<cfset a = [] />
<cfloop index="x" list="1.1.2.1.3" delimiter=".">
<cfset temp = a[arraylen(a)] />
<cfset temp = listappend(temp,x,".") />
<cfset arrayAppend(a,temp) />
</cfloop>

--
s. isaac dealey  ^  new epoch
 isn't it time for a change?
     ph: 781.769.0723

http://onTap.riaforge.org/blog



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1192
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21

Re: [URGENT] Incremental matches!

by Peter Boughton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Thanks Adrian, No actually I am using Java Regex but I think they are alike.
> I want not to use any for loop

Why not?

Can you provide more context as to what you're actually doing? It
might enable a better answer.


You can do:
^\d for 1
^\d(\.\d){1} for 1.1
^\d(\.\d){2} for 1.1.2
^\d(\.\d){3} for 1.1.2.1
etc

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1193
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21

Re: [URGENT] Incremental matches!

by is_maximum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, I have a tree structure in database in which each node has its own unique id as above, say 1.1.1.2.1 now by given a node and its position (the same id) I have to extract all its parents and return back to the client. the parents' ids are identified by that unique id (1, 1.1, 1.1.1 AND 1.1.1.2) if it was only one node there was no problem using a for loop but we may have hundreds of these nodes and should extract all of them each for a user concurrently and this is a performance issue

now I am welcome if you can help me on this with anything better than Regex

thanks

Peter Boughton wrote:
> Thanks Adrian, No actually I am using Java Regex but I think they are alike.
> I want not to use any for loop

Why not?

Can you provide more context as to what you're actually doing? It
might enable a better answer.


You can do:
^\d for 1
^\d(\.\d){1} for 1.1
^\d(\.\d){2} for 1.1.2
^\d(\.\d){3} for 1.1.2.1
etc

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1193
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21
-- Regards
Mohammad Norouzi
Help each other to reach the future faster
Pixelshot Photoblog
Brainable Blog

Re: [URGENT] Incremental matches!

by is_maximum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well
Chris Porter, has just replied me with a smart solution but I can't test it right now until I get to work. I don't know why he can't post here.

this is the solution:

select *
from NODE_TABLE
where '1.1.1.2.1' like id + '%' and id not like '1.1.1.2.1%'

We are using OpenJPA and Oracle database. I am eager to check if it works well

Thanks all

-- Regards
Mohammad Norouzi
Help each other to reach the future faster
Pixelshot Photoblog
Brainable Blog

Re: [URGENT] Incremental matches!

by is_maximum :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

well guys
this works fine thank you all

select *
from NODE_TABLE
where '1.1.1.2.1' like id + '%' and id not like '1.1.1.2.1%'

-- Regards
Mohammad Norouzi
Help each other to reach the future faster
Pixelshot Photoblog
Brainable Blog