The Artima Developer Community
Sponsored Link

Java Answers Forum
Regex-style for non-text?

1 reply on 1 page. Most recent reply: Jul 7, 2005 7:13 PM by Antonio

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Calum MacLean

Posts: 9
Nickname: calummacle
Registered: Feb, 2003

Regex-style for non-text? Posted: Jul 1, 2004 1:56 AM
Reply to this message Reply
Advertisement
I have a sequence of "objects" which must occur in a certain order, with optional items etc.

As I've been using regex's quite a bit of late, it struck me that it might be useful to do a similar thing for arbitrary objects, rather than just for text characters.

For example, if I have objects A, B, C, D and E, and:


they must occur in the sequence in that order (if present)
B is optional
exactly one of D and E must be present.


then it would be nice to be able to specify this as "AB?C[DE]" - or something equivalent.

Does this make sense? Do you know if there are any libraries available to allow you to do this sort of thing?

Thanks,
Calum


Antonio

Posts: 33
Nickname: arhak
Registered: Jul, 2005

Re: Regex-style for non-text? Posted: Jul 7, 2005 7:13 PM
Reply to this message Reply
What are A, B, C, D and E?
Classes Names or instances?
Because they are y upercase I assume they are Classes so I'm thinking in an Object array target and the need of know if it complains that regex.
If so: why don't you concat the array elements getClass().getName() and try to match the following regex:
String regex  = A.getClass().getName()+B.getClass().getName()+"?"+C.getClass().getName()+"["+D.getClass().getName()+E.getClass().getName()+"]"


I mean, convert your problem in terms of Strings.

Flat View: This topic has 1 reply on 1 page
Topic: Java Runtime Environment Previous Topic   Next Topic Topic: BasicSplitPaneDivider.DividerLayout

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use