Beginner question about Regular expression

Hi all !
I'd like to use a regular expression to parse a string like this:
*<ID>4</ID><GROUP>5</GROUP>....*
So for example to retrieve the ID I have built the following regular expression:
Pattern p = Pattern.compile("<ID>(.*?)</ID>");  
Matcher m = p.matcher(handle);    
if (m.find()) {
      System.out.println("->"+m.group());     
} else {
System.out.println("No match!");   
}The function m.group returns "<ID>4</ID>" but I want just the value (4) between the tag. Is there
a way to get it ?
thanks a lot
mark

fmarchioniscreen wrote:
thank you very much, that's exactly what I needed.
But it looks like you're parsing some XML like data: probably better to use a proper parser on it. Well it's a very short string containing XML tags. it's used in a marginal area of the application so I prefer just using a regular expression to fetch the values
thanks again
MarkYou could use XPath to get the value.

Similar Messages

  • Basic question about regular expressions

    Hello,
    I am a beginner to regular expressions. I want to rewrite the following expression:
    public static final String REGULAR_EXP_SOFTWARE_PART_NUMBER = "([0-9]{7}[a-z]{1})(\\-{1})([a-z]{1})";I want THIS match
    (\\-{1})to occur EITHER if a hyphen is encountered OR if a space is encountered (instead of just the hyphen).
    How do I rewrite this?
    Thanks in advance,
    Julien.

    Hello and thanks for your feedback,
    I have created a small class as follows:
    package regExpr;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    * @author Martin
    public class RegExprTest {
         private static String stringToBeParsed = "3800157w-e26";
         public static void main(String[] args) {
              Pattern pattern = Pattern.compile("" +
                        "([0-9]{7})" +
                        "([a-z]{1})" +
                        "(( |-){1})" +
                        "([a-z]{1})" +
                        "([0-9]{2})" +
              Matcher matcher = pattern.matcher(stringToBeParsed);
              while(matcher.find()){
                   System.out.println(matcher.group(1));
                   System.out.println(matcher.group(2));
                   System.out.println(matcher.group(3));
                   System.out.println(matcher.group(4));
                   System.out.println(matcher.group(5));
                   System.out.println(matcher.group(6));
    }the class is trying tobreak down the following string "3800157w-e26" as follows:
    3800157(seven digits)
    w(one letter)
    -(hyphen)
    e(one letter)
    26(two digits)
    Oddly enough the output of the class is as follows:
    3800157
    w
    e
    26
    I have to call the group method six times and I get two hyphens!
    Can anyone help?
    Thanks in advance,
    Julien

  • Question about Regular Expressions, please help!

    I have created an app which reads files and extracts certain data using regular expressions in JDK1.4 using Pattern and Matcher classes.
    However it needs to run on JDK1.2.2 (dont ask). The regular expression classes are not available in 1.2.2 (the Pattern and Matcher class) so i am looking for something similiar which i can use?
    I need something that loops through all the matches found in the file like how Matcher works i.e.
    while (matcher.find())
    // do this
    Help!

    http://jakarta.apache.org/regexp/

  • Simple question about regular expressions

    Hi,
    Using Java's regular expression syntax, what is the correct pattern string to detect strings like the following :-
    AnnnnnA
    where A = a single (fixed) alphabetic character and
    n = at least one but possibly many digits [0-9].
    Example strings to be searched :-
    A45A (this should match)
    A3A (this should match)
    A3446655577A (this should match)
    A hello world A (this should NOT match as no digits are present between the A's).
    Thanks.

    A least one digit "A.*\\d.*A"
    Only digits "A\\d+A"

  • One question about Regular Expression!!!

    I need to creat such a regular expression to match the format "[ ][ ][ ]".
    For example, there is a context,
    (1), " The project manager defines [1][0.400][+goals] for iterations."
    Suppose that there are some spaces or "\n" characters in this way,
    (2), " The project manager defines [    1 ] [  0.400   ]
    [   +goals] for iterations."
    If the pattern match the format succefully, (2) strings should be replaced by (1)strings, in order words, the format of (1) is what I need finally,
    I had ever tried creating a regular expression likes \\[([^\n\s]]+)\\]\\[([^\n\s]]+)\\]\\[([^\n\s]]+)\\] , but it does not work well!
    DO YOU HOW TO IMPLEMENT IT IN JAVA?
    Thanks for your any reply!

    What I really need is that, via the regular
    expression, all the spaces and \n characters in
    square brackets [ and ], ] and [, will be thrown
    away.
    For example,
    Original:
    1) "The project manager defines [   1  ] [
    0.400 ]
    [   +goals] for iterations with the support"
    After matching:
    2) "The project manager defines [1][0.400][ [+goals]
    for iterations with the support"
    String 2) is what I need finally!
    Thanks for your any reply!Well I gave you the answer to that one already :-)
    If you need to preserve the spaces in between words use this one. I'm sure there's a better way to do it, I'm no RegEx master.
        public static void main(String[] args)
            String s = "[ 1 ] [ 0.400 ]\n[ +go als]";
            System.out.println( "Before: " + s );
            System.out.println( "\n\n" );
            s = s.replaceAll( "\\[\\s+", "[" );
            s = s.replaceAll( "\\s+\\]", "]" );
            s = s.replaceAll( "\\]\\s+\\[", "][" );
            System.out.println( "After: " + s );
        }

  • An additional question about regular expressions with String.matches

    does the String.matches() method match expressions when some substring of the String matches, or does it have to match the entire String? So, if i have the String "123ABC", and i ask to match "1 or more letters" will it fail because there are non-letters in the String, but then pass if i add "1 or more letters AND 1 or more digits"? so, in the latter every character in the String is accounted for in the search, as opposed to the first. Is that correct, or are there ways to JUST match some substring in the String instead of the whole thing? i WILL make some examples too... but does that make sense?

    It has to match the whole String. Use Matcher.find() to match on just a sub-string()

  • Simple question about regular expression

    Hi
    I have a little problem with
    select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
    answer: M
    I excecute this query in SQLPlus and SQL Developer result is this same.
    select regexp_substr('123 Mapla Avenue','[M]') my_test from dual;
    answer: M
    select regexp_substr('123 Mapla Avenue','[a]') my_test from dual;
    answer: a
    I used oracle 10g
    Thanks for your help

    hm wrote:
    In the oracle documentation of regexp_substr you can find:Do not confuse pattern and sort. Pattern [a-z] means any lowercase letter. REGEXP_SUBSTR parameter match_param value i tells REGEXP to treat uppercase letters same as lowercase letters and vice versa. And setting NLS_SORT can do the same. As you can see it is not that straight-forward. To make it transparent use exact pattern you need. In this particular case use:
    select regexp_substr('123 Mapla Avenue','[[:alpha:]]') my_test from dual;where class [:alpha:] is POSIX predefined class of all letters (regardless of case). This way you are not dependent of client side settings like NLS_SORT and the above will always return first letter within a string. If you want first uppercase letter use:
    select regexp_substr('123 Mapla Avenue','[[:upper:]]') my_test from dual;Or, for first lowercase letter:
    SQL> alter session set nls_sort=binary;
    Session altered.
    SQL> select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
    M
    a
    SQL> select regexp_substr('123 Mapla Avenue','[[:lower:]]') my_test from dual;
    M
    a
    SQL> alter session set nls_sort=binary_ci;
    Session altered.
    SQL> select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
    M
    M
    SQL> select regexp_substr('123 Mapla Avenue','[[:lower:]]') my_test from dual;
    M
    a
    SQL> SY.

  • Question about Regular Expressions

    Hi averyone!
    Could any one help me to create RegEx for string: <object>
    Thanks!
    Kind Regards, Dmitry.

    "<object>"

  • Off Topic: Books about Regular Expression

    Hi
    Somebody can to indicate books about Regular Expression in Oracle ?
    Thanks

    Regex tag of Blog of Volder.
    http://volder-notes.blogspot.com/search/label/Regular%20Expressions
    This entry mentions my regex solution :-)
    http://volder-notes.blogspot.com/2007/10/removing-duplicate-elements-from-string.html
    By the way
    My regex homepage mentions regex problems of perl like regex (regex of EmEditor).
    http://www.geocities.jp/oraclesqlpuzzle/regex/
    example questions (written by Japanese language)
    http://www.geocities.jp/oraclesqlpuzzle/regex/regex-2-1.html
    http://www.geocities.jp/oraclesqlpuzzle/regex/regex-3-5.html
    http://www.geocities.jp/oraclesqlpuzzle/regex/regex-4-4.html

  • Two Questions about Airport Express

    All, I am a recent convert to using a Mac so bear with me.
    I have two questions about the Airport Express.
    Question if I buy one in the USA, I will visiting this week on holiday,can I use it the UK with a UK adaptor/apple plug?
    Can the Express be used with my current wireless network, using a Netgear DG834G V4, I have read lots in the forums about putting a $ sign in front of the WPA password?
    Any help and advice gratefully received.

    Tesserax wrote:
    Hello andixbox. Welcome to the Apple Discussions!
    Question if I buy one in the USA, I will visiting this week on holiday,can I use it the UK with a UK adaptor/apple plug?
    Yes, but at least two things to consider:
    o The US version of the 802.11n AirPort Express Base Station (AXn) only supports radio channels 1-11 in the 802.11g radio mode. Channels 12-14, used in other countries outside the US will not be available.
    o The AXn supports both the 2.4 and 5 GHz radio bands for 802.11n. The 5 GHz band is restricted in certain countries (like the UK) so operating in this mode may get you unwanted attention.
    That should be okay then because the Netgear broadcasts on channels 1-11. I hadn't appreciated the 5 Ghz band, but having checked both US and UK Apple sites the techspecs both mention 2.4 Ghz and 5 Ghz.
    Can the Express be used with my current wireless network, using a Netgear DG834G V4, I have read lots in the forums about putting a $ sign in front of the WPA password?
    If your intent is to have the AXn join the Netgear as a wireless client, then yes it should work. The "$" requirement was for WEP. This shouldn't be necessary for WPA or WPA2.
    I intended to use the AXn as an range extender, but you mention wireless client, is that something different?

  • Question in regular expressions

    Hi,
    I have this string (abdcerpabdcerpabdcerpaabdcerpabdcerp)
    and i want to this string abdcerp and may be followed by one or more a's
    So i want to get these results:
    abdcerp
    abdcerp
    abdcerpa
    abdcerp
    abdcerp
    I know regular expressions very well but i failed to generate one that can do so. I tried using this regex (abdcerpa*?) but it failed. it's not working and i dont know why, it's not getting abdcerpa. It only gets abdcerp
    can anyone help me with that telling me the reson why did this regex is not good or tell me a regex for doing so. But I need it to be tested cause I already know about the concepts and tried different ways and regexs but failed
    thanks
    bye

    That forum was retired and is now read-only. According to the announcement;
    Any future posts on this topic should be put in the 
    .NET Framework Class Libraries forum.
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • Strange result about regular expressions

    Hello everybody,
    I write these codes to try regular expressions in Java, but there are some strang results. I read the reference like Sun Java Tutorials. however, I cann't find the problem.
    Environnement:
    WindowsXP Home + NetBeans IDE 5.0 + JDK 1.5
    Input String:
    "I write these codes to try regular expressions in Java, but it doesn't work. I read some reference like Sun Java Tutorials. Then, always cann't find the problem. Could you help me? Thanks."
    My codes:
    public static void main(String[] args) throws Exception, IOException {
    P.rintln("Let's go!");
    Date start = new Date();
    if(args.length != 1) {
    P.rintln("Input Error! Input format: java javaclass [directory path]");
    System.exit(0);
    StringBuffer sb = new StringBuffer();
    String input = TextFile.read(args[0]);
    sb = addSectionEelement(input, "re");
    P.rintln(sb.toString());
    P.rintln("Ok, it's over");
    Date end = new Date();
    System.out.println("It spends " + (end.getTime() - start.getTime()) + " ms.");
    public static StringBuffer addSectionEelement(String input, String regex) {
    Matcher m = Pattern.compile(regex).matcher(input);
    StringBuffer sb = new StringBuffer();
    int count = 0;
    while(m.find()) {
    count++;
    P.rintln(m.group());
    P.rintln("Found " + count + " fois.");
    return sb;
    Output:
    run:
    Let's go!
    Found 0 fois.
    Ok, it's over
    It spends 16 ms.
    BUILD SUCCESSFUL (total time: 0 seconds)
    However if I change the Bold line by
    sb = addSectionEelement(input, "r");
    The resultats become:
    run:
    Let's go!
    r
    r
    r
    r
    r
    r
    r
    r
    r
    r
    r
    Found 11 fois.
    Ok, it's over
    It spends 15 ms.
    BUILD SUCCESSFUL (total time: 0 seconds)
    I have no idea about it. And you?
    Thanks

    Hi guys,
    I re-examine the codes. In fact, it's the problem of encodings of the input file.
    See u

  • About regular expressions

    This question was posted in response to the following article: http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a38 f-7fff.html

    "ColdFusion supplies four functions that work with regular expressions" should be "ColdFusion supplies six functions that work with regular expressions,"

  • Help About Regular Expression.

    Hello,
    I am trying to parse string buffer by using Regular Expression.
    Suppose my string buffer is:
    Hi , How are you?
    Hello: abc
    hurrey : [ this is test msg
    Pls reply to this mail
    Hello: xyz
    Test1
    I want to search string: "Hello: anystring till end of line" which is
    not included in [].
    So In above example my Regular expression should only find
    first "Hello: abc".
    Is it possible by using Regular expression?

    Can we have Regular Expression which will get both "Hello: string"
    suppose my string buffer is:
    Hi , How are you?
    Hello: abc
    hurrey : [ this is test msg
    Pls reply to this mail
    Hello: xyz
    Test1
    happy: [ test2
    my test
    Hello: abc
    then result should be :
    Hello: abc
    [ this is test msg
    Pls reply to this mail
    Hello: xyz
    Test1
    [ test2
    my test
    Hello: abc
    ]

  • Question about FC Express

    Hi all.
    I have no FC experience.....just some iMovie putzing with the family video's. I do use Photoshop CS5 and have years of experience with Pro Tools and work in film/TV production so I am not a total stranger to filmmaking and audio production, using difficult software etc etc. I spend hours every day in my music studio or editing photo's and minor video editing. Nothing deep like FCP though. I hear the FCP learning curve is brutal.
    Anyway, I am dabbling with writing music aimed at soundtrack stuff for film, TV and commercials and am wondering about FC Express.
    Would it be a good program to learn about dropping music into a video timeline?
    I was thinking about trying to put together some stuff I shoot, Mini DV and Flip HD stuff and then write music for it to practice with. I'd also like to try and come up with markers and hit points and all so that as I get better I don't look like a total bozo when I try to get a short or low budge Indie or student film to score.
    What I would really like to do is get some footage with dialogue and audio effect already mixed and then write to that.
    I have friends who work in post who have agreed to look around for some stuff for me to work with. If they were to give me sections of FCP sessions, would I be able to open those in Final Cut Express?
    Also, I read that FCE 4 does not have Soundtrack that 3.5 HD has. Is this a detriment and can one still buy 3.5 or has it been replaced with v4?
    Thanks.
    Message was edited by: Fumblyfingers

    FCE should do much of what you require.
    However, be warned. It is exactly the same app as FCP with a few items removed.
    So for "normal" editing the learning curve is identical.
    You will not be able to open FCP projects in it.
    If you need Soundtrack you should be able to buy a cheap FCE 3.5 Upgrade on eBay etc. and just install Soundtrack.

Maybe you are looking for

  • IBook Clamshell video out modification

    I recentley purchased an iBook Clamshell with out video out and I really need video out. I was wondering if I was to replace the sound board in my graphite ibook with the video board from a key lime ibook would it enable me to use video out. Also if

  • Outlook 2013 won't sync thru iCloud -- workaround

    On a Windows 8 PC, Outlook 2013 will not sync calendar and contacts with i devices thru iCloud.  Until Apple and/or Microsoft address the compatibility issue, there is a reasonable workaround.  Use Outlook 2013 only for mail.  For calendar  and conta

  • Clock or Alarm Clock?

    I recently gave up my 8350i for an 8330m, and I'll be darned if there aren't a couple of features I miss from the 8350i!!  The one I miss the most is the clock.  On the 8350i, I have a full-fledged clock - complete with alarm clock, stopwatch, timer,

  • I can not export from phosotshop elements 10 and premier elements 10

    I have windows 8, my computer is new and came with photoshop and premier elements 10 installed, but I cannot export anything, I can see the option under files tag, but I cannot select it, it appears in a lighter grey. Thank you

  • Wifi not displaying even thought wifi network is available.

    i installed lan drivers related to my laptop version hp 15 r204tu. even after that wifi icon is not displaying in my laptop.Please help me in this issue.. Note: recently i changed the os from win 7 ultimate to win 7 professional. Earlier it is fine.