Re: Regular expression in Java
The87Boy wrote:
On 3 Feb., 18:38, Lew <no...@lewscanon.com> wrote:
The87Boy wrote:
I am trying to create a new profile management system, and I have some
regular expression I used in PHP e.g. "<\/b> (.*?) aar"
Where I get the String between and aar
Is there any way I can do this in Java?
Yes.
Eric Sosman wrote:
There's a splendid new on-line system for answering this
kind of question. Visithttp://www.google.com/(that'stwo O's
and one G, not the other way around) and enter a search for, oh,
gee, I dunno, maybe "Regular expression in Java". Chances are
Very Good Indeed that they'll have something you can make use of.
Lew wrote:
You mean, like
<http://java.sun.com/javase/6/docs/api/java/util/regex/package-frame.html>
?
Did you read this link? Have you read through the descriptions of the various
types and methods in that package?
Yes I have
The87Boy wrote:
Yes, but I don't know I should make use of it in my situation
Neither do we. You haven't seen fit to share any details. What exactly is
your situation?
I use the regular expression "<\/b> (.*?) aar" in PHP to get the
String between the space and aar (the .*)
I want to use it in the same way in Java
I could of course split the String up 2 times
What are your specific questions about the Java regex libraries?
Whatever it is possible to find a String from another String by a
regular expression in Java
What have you tried so far?
I have tried many thing, but it seems that I have to split the String
import java.util.regex.*;
public class test {
public static void main(String[] args) {
String str =
"Some where over the </b> There is a duck aar from here to there";
Pattern p = Pattern.compile("</b> (.*?) aar");
Matcher m = p.matcher(str);
if (m.find())
System.out.println(m.group(1));
}
}
You don't have to split the string. I don't use PHP but it looks like
you need to escape the forward slash? That is not required in Java.
Look at Pattern and Matcher in the docs.
--
Knute Johnson
email s/nospam/knute2010/