Or the equivalent: public String takeit(String input, String tag) { Pattern p = Pattern.compile(".*?<(" + tag + ")>([^<]*)</\\1>"); Matcher m = p.matcher(input); return m.matches() ? m.group(2) : null; }
R/ On Thu, Mar 12, 2009 at 1:34 PM, EECOLOR <eeco...@gmail.com> wrote: > I think that would be something like this: > > public String takeit(String str, String tag) > { > return str.replace(".*?<" + tag + ">(.*?)</" + tag + ">.*", $1); > } > > Greetz Erik > > On Thu, Mar 12, 2009 at 7:14 PM, guruk <ilovesi...@gmail.com> wrote: >> >> Hi, >> i have a long String and need to capture some text in between of some >> tags. >> >> for example: >> >> myString="Hello, this is a test <start>12345</start> and here i like >> to say <marki>oioidddad</marki> what is that <opxmark>notwise</ >> opxmark> and now i close"; >> >> How would you do in java regex or any short thing like: >> >> starttag = takeit(myString,"start"); //result = "12345" >> marktag =takeit(myString,"marki"); //result = "oioidddad" >> opxmark=takeit(myString,"opxmark"); //result == "notwise" >> >> thanks a lot from your java newbie :) >> >> chris >> >> >> >> >> > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---