RE and Jar are hard to Google for!

P

Phlip

Java-istas:

"Re" is a common prefix for post subjects, and "jar" is a cylindrical
open-mouthed kitchen vessel. I can't Google for what library to add to
my project to get Regular Expressions, in Java (which is an island
with a really cool temple on it, Borubador).

Apologies for the helplessly newbescent question, but how do I get
RegExps around here?
 
P

Phlip

Skip said:
Search on
"Regular Expression" java jar
and you will see jakarta has a jakarta-regexp.jar and
jakarta-regexp-package.jar files for ya. Happy Parsing.

<screaming>Do you mean to tell me that Java has spent the last 8 years
contending with Perl for the Number One Web Language niche WITHOUT a native
RegExp library???</screaming>

<tiny_little_voice> thanks for the linkie... </tiny_little_voice>
 
P

Phlip

Marco said:
There is java.util.regex in the runtime library.

What I can't figure is why JUnit doesn't have assertMatch().

The only Googling for 'JUnit assertMatch' I done found used RE instead of
regex.

So here's the version using the most-standard library:

import java.util.regex.Pattern;
....
private void assertMatch(String regex, String input) throws Exception
{
boolean shouldMatch = Pattern.matches(regex, input);
assertTrue("<" + regex + "> should match <" + input + ">", shouldMatch);
}

None of this is a technical question anymore - thanks guys.
 
P

Phlip

So here's the version using the most-standard library:
import java.util.regex.Pattern;
...
private void assertMatch(String regex, String input) throws Exception
{
boolean shouldMatch = Pattern.matches(regex, input);
assertTrue("<" + regex + "> should match <" + input + ">", shouldMatch);
}

Now what if I called that like this:

String patter = "(happy){2} (joy){2}";
assertMatch(patter, getRenState());

Now what if I want the console, at fault time, to display this:

(patter)<(happy){2} (joy){2}> should match
(getRenState())<You fat, bloated eediot!>

To put the names of the source expressions into the console, we must get
them from the source of the calling method. How?

(Flame: C++ can do this with the mighty stringerizer operator..)
 
D

Dale King

Phlip said:
<screaming>Do you mean to tell me that Java has spent the last 8 years
contending with Perl for the Number One Web Language niche WITHOUT a native
RegExp library???</screaming>

No, Java spent the first 6-7 years of its life without a regular expression
library as part of its core library. For the past year and a half it has had
one in java.util.regex. Before that you had to use one of the many freely
available third party ones. Personally I would recommend the Jakarta ORO
project over the regexp project.
 
D

Dale King

Phlip said:
What I can't figure is why JUnit doesn't have assertMatch().

Because then it would not be compatible with pre-1.4 VM's or else require a
third party library.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top