Re: need Help Regex



Thanks Chris.
But actually I need to do it using Regular Expressions.


"Chris Chilvers" <keeper@xxxxxxxxxxx> escribió en el mensaje
news:1onba2hdvrg2o1rcla5jgp8turh1h1nv63@xxxxxxxxxx
On Fri, 30 Jun 2006 14:09:55 +0200, "JM" <jm06@xxxxxx> wrote:

Hi,

I am not sure if this is the place to post a REGEX question if not, please
indicate me where i can post it?.

My question:
Given a string like: "Boston. MA. Holidays" I need to define the regular
expression to find each dot, the previous word and the word after. That is
i
want to obtain:

first match: "Boston" "." "MA"
second match: "MA" "." "Holidays"

The problem is that if I use somthing like: ([^\s\.]+)(\.)(\s*[^\s\.]+) I
"cosume" MA in the first macth so I do not have a second match. That is I
obtained:

first match: "Boston" "." "MA"
and no more matches, since MA is consumed in the previous match.

Any help??

Thanks,
jaime


Could a simpler implementation not be to split by ".", then you will
have an array of strings that you can just move through a pair at a time
running the trim function to remove whitespace.

Example
========

string[] parts = full_string.Split('.');

if (parts.length > 2) {
string a = parts[0].Trim();
string b = parts[1].Trim();

DoSomething(a, b);

for (i = 2; i < parts.Length; i++) {
a = b;
b = parts[i].Trim();

DoSomething(a, b);
}
}

========


.



Relevant Pages

  • Re: need Help Regex
    ... I am not sure if this is the place to post a REGEX question if not, ... Given a string like: "Boston. ... "cosume" MA in the first macth so I do not have a second match. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Serious Perl Regular Expression deficiency?
    ... I started doing Perl 2 years ago and have ... > conclusion that regular expressions have a serious ... This is serious because the not string ... If you want to pull out the contents of XML comments you could do this. ...
    (comp.lang.perl.misc)
  • Re: Remove characters from string
    ... and your link took me to the templates page at microsoft office. ... there expaining regular expressions unless you meant I should search for it. ... | them to the same format for ease of processing. ... | the string I remove extraneous characters. ...
    (microsoft.public.excel.programming)
  • Re: combining millions of different regular expressions
    ... match a given string with all of them some how. ... merged state machine will have an optimal structure to improve the ... First, be careful with what you mean by matching regular expressions, ... (One of those cases where theory and practice mis-align.) ...
    (comp.theory)
  • Re: dividing an replacing spaces in string
    ... I knew regular expressions would help in this. ... This newly delimited string will dump into separate rows like this ... Dim colMatches As Object ... Set objRe = CreateObject ...
    (microsoft.public.excel.programming)