Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > A question about regular expressions

Reply
Thread Tools

A question about regular expressions

 
 
Covington Bradshaw
Guest
Posts: n/a
 
      12-23-2006
Hi every one,

I have a basic regular expressions question.
It goes like this: How do I extract a sequence of
@-delimited characters from a text?

Example: @{1}.*?@{1}
Will give:
123456789abcdefhghij
when applied to the following text:
@123456789abcdefghij@987654321stuvwxyz@

However I am trying to build a regular expression
for a more complex case where the double @@, which
is the escape character for @, can also be handled.
Consequently I need to know how to extract

123456789@@abcdefhghij

from

@123456789@@abcdefghij@987654321@@stuvwxyz@

using regular expressions.

Note the expression @([^@]|((@@)*))@ was suggested in a
previous reply but this one returns a false positive
on the following text:

@123456789@@abc

by returning the value:
@123456789@

Anyone has a clue?

Thanks
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      12-23-2006
Covington Bradshaw <(E-Mail Removed)> wrote:
> Hi every one,
>
> I have a basic regular expressions question.


Yes. Can you do us a favor and respond in existing threads, instead of
starting new ones all the time? Do you know how to reply to an existing
message?

> Note the expression @([^@]|((@@)*))@ was suggested in a
> previous reply but this one returns a false positive
> on the following text:
>
> @123456789@@abc


Okay. Then try (^|[^@])@([^@]|((@@)*))@($|[^@])

This time, your result will be in group #2.

--
Chris Smith
 
Reply With Quote
 
 
 
 
Covington Bradshaw
Guest
Posts: n/a
 
      12-23-2006


public static void main(String[] args) {
Pattern pattern = Pattern.compile("(^|[^@])@([^@]|((@@)*))@($|[^@])", Pattern.DOTALL);
String b = "@123456789@@abcdefghij@987654321@@stuvwxyz@";
Matcher matcher = pattern.matcher(b);
System.out.println("find [" +matcher.find() + "]");
System.out.println("group [" + matcher.group() + "]");
System.out.println("start [" + matcher.start() + "]");
System.out.println("end [" + matcher.end() + "]");
}

This code returns 9@@a

I am expecting @123456789@@abcdefghij@

Am I missing something?

=======================
>
> Okay. Then try (^|[^@])@([^@]|((@@)*))@($|[^@])
>
> This time, your result will be in group #2.


 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      12-24-2006
Covington Bradshaw <(E-Mail Removed)> wrote:
> This code returns 9@@a
>
> I am expecting @123456789@@abcdefghij@
>
> Am I missing something?


Nah. I just screwed up, and didn't realize it. This one is actually
tested:

(^|[^@])@(([^@]|(@@))+)@($|[^@])

Again, answer in group #2.

--
Chris Smith
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expressions Question. questionmarc420@msn.com Java 9 01-23-2006 10:32 PM
Question on regular expressions ASP.Confused ASP .Net 2 07-26-2004 04:14 PM
XML schema regular expressions question and recommended XML Schema book Fred Smith XML 1 02-05-2004 11:12 AM
Another Regular Expressions question jeffM Java 3 02-02-2004 11:03 PM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM



Advertisments