Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Regular Expressions
This is the forum to discuss the Wrox book Beginning Regular Expressions by Andrew Watt; ISBN: 9780764574894
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Regular Expressions section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 19th, 2011, 02:48 PM
Authorized User
Points: 134, Level: 2
Points: 134, Level: 2 Points: 134, Level: 2 Points: 134, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pattern match help!

Hi,

I have strings in the format given below: I need to match -> one pair of Line String i.e from the Example below:

MULTILINESTRING ((175.641715 -40.860575, 175.641908 -40.860854), (185.641715 -45.860575, 182.641908 -35.860854))



Note: A multi line string can have any number of line strings.

I need to match:

Match 1 : 175.641715 -40.860575, 175.641908 -40.860854

Match 2 :185.641715 -45.860575, 182.641908 -35.860854
and so on...


Thanks,

Any help is greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old October 18th, 2012, 08:04 PM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by cooltechie View Post
Hi,

I have strings in the format given below: I need to match -> one pair of Line String i.e from the Example below:

MULTILINESTRING ((175.641715 -40.860575, 175.641908 -40.860854), (185.641715 -45.860575, 182.641908 -35.860854))



Note: A multi line string can have any number of line strings.

I need to match:

Match 1 : 175.641715 -40.860575, 175.641908 -40.860854

Match 2 :185.641715 -45.860575, 182.641908 -35.860854
and so on...


Thanks,

Any help is greatly appreciated.
There are a few details you don't explain clearly, but I have assumed that your data is line orientated with each line being composed of many pairs of pairs of (co-ordinates?) surrounded by brackets. Here is a perl implementation of that:

Code:
`#!/usr/bin/perl
use strict;
use warnings;
use 5.10.0;  # for "say"

my $string = "((175.641715 -40.860575, 175.641908 -40.860854), (185.641715 -45.860575, 182.641908 -35.860854))\n"
             . "((175.641715 -40.860575, 175.641908 -40.860854), (185.641715 -45.860575, 182.641908 -35.860854))";

my $pair = qr{[-]?\d+\.\d+ [-]?\d+\.\d+};          # match a pair of (co-ordinates on cartesian plane)?
my $dbl_pair = qr{$pair, $pair};                   # match two pairs sepearted by a space
my @matches = ($string =~ m{\(($dbl_pair)\)}gso);  # match any number of pairs surrounded by brackets and assign all to matches

map {say} @matches;                                # map the function say over each element of matches, effectively printing 
                                                   # them out one per line

For the string in the file (the one in your question, repeated twice with a newline between the repetitions) this gives

Code:
$ perl mst.pl
175.641715 -40.860575, 175.641908 -40.860854
185.641715 -45.860575, 182.641908 -35.860854
175.641715 -40.860575, 175.641908 -40.860854
185.641715 -45.860575, 182.641908 -35.860854
Which seems to meet the requirement.
__________________
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
State pattern versus Strategy Pattern disel2010 BOOK: Professional ASP.NET Design Patterns 2 March 15th, 2011 09:20 AM
Regex pattern to match carriage returns inside quotation marks? miikee55 Classic ASP Basics 4 September 21st, 2009 07:04 AM
Pattern extension? tdewey BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 1 May 13th, 2009 11:20 PM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 07:24 AM
DirectoryInfo.GetFiles(pattern): search pattern fo arif_1947 VS.NET 2002/2003 1 October 20th, 2004 12:59 AM



All times are GMT -4. The time now is 05:45 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.