Results 1 to 9 of 9
Thread: regular expression
- 01-15-2010, 05:22 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 9
- Rep Power
- 0
regular expression
In java regular expression, is it possible to reference one previous part of this pattern, or is it possible to make the comparison of two parts of a pattern.
For example, here is the Days Starttime-Endtime pattern
^(M?T?W?R?F?S?U?\\s(([01]\\d|2[0-3])[0-5]\\d\\-([01]\\d|2[0-3])[0-5]\\d))$
here is a valid office hours:
MWF 0800-1000
here should be an invalid office hours:
MWF 1100-1000
Because endtime should be after start time.
The real question is:
can we implement start time before end time through pattern?
Thanks.
- 01-15-2010, 11:30 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I don't think with a RegEx this is possible, may be in a complex manner. Why don't you do simple string manipulation, separate the start-end times and process.
- 01-18-2010, 02:14 AM #3
Member
- Join Date
- Aug 2009
- Posts
- 9
- Rep Power
- 0
Yep. Seems that one possible solution is to get the capturing groups with matcher.group, then doing the comparison between 2 groups and throw the exception
- 01-18-2010, 03:46 AM #4
Sorry dude, but like Eranga said, I don't think it's possible. I looked over some conditional, lookahead, lookbehind and there's nothing that would check if a backreference is greater than another backreference
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 01-18-2010, 07:55 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Indeed, regular expressions can't do any numerical calculations; e.g. see the mess how to specify a number in the range [0,23]. REs can recognize regular patterns in Strings. But on top of those REs there's Java that can do the non-regular condition checks.
kind regards,
Jos
- 01-18-2010, 10:22 PM #6
yea it does look like a mess, but regex's (in my opinion) autonomy is just prodigious. It doesn't rely on a programming language. It's like an interface and is implemented by many languages. Regex is probably one of the things that I love about programming in general.
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 01-19-2010, 07:50 AM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 01-19-2010, 02:23 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
- 01-20-2010, 03:55 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
regular expression
By ras_pari in forum Advanced JavaReplies: 27Last Post: 10-07-2009, 12:25 PM -
Basic regular expression help
By predhme in forum New To JavaReplies: 1Last Post: 06-26-2009, 01:29 AM -
need help to make this regular expression
By aruna1 in forum New To JavaReplies: 1Last Post: 04-12-2009, 08:09 PM -
Regular Expression Challange
By hiklior in forum New To JavaReplies: 2Last Post: 04-24-2008, 05:05 AM -
regular expression for unicode
By tharhan in forum Advanced JavaReplies: 0Last Post: 04-01-2008, 10:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks