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 );
    }

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

  • 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"

  • 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/

  • 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.

  • 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()

  • Question about Regular Expressions

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

    "<object>"

  • 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.

  • 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

  • One question about Pricing and Conditions puzzle me for a long time!

    One question about Pricing and Conditions puzzle me for a long time.I take one example to explain my question:
    1-First,my sale order use pricing procedure RVAA01.
    2-Next,the pricing procedure RVAA01 have some condition type,such as EK01(Actual Costs),PR00(Price)....,and so on.
    3-Next,the condition type PR00 define the Access Sequences PR00 as it's Access Sequences.
    4-Next,the Access Sequences PR00 have some Condition tables,such as:
         table 118 : "Empties" Prices (Material-Dependent)
         table 5 : Customer/Material
         table 6 : Price List Type/Currency/Material
         table 4 : Material
    5-Next,I need to maintain Condition tables's Records.Such as the table 5(Customer/Material).I guess the sap would supply one screen for me to input the data of table 5.At this screen,the sap would ask me to select one table,such as table 5.When I select the table 5,the sap would go to the screen to let me input the data of table 5.But when I use the T-CODE VK31 or VK32 to maintain Condition tables's Record,I found it's total different from my guess:
    A-First,I can not found one place for me to open the table,such as table 5,to let me input the data?
    B-Second,For example,when I select the VK31->Discounts/Surcharges->By Customer/Material,the sap show the grid view at the right side.At the each line of the grid view,you need to select the Condition Type at the first field.And this make me confused very much.Why the sap need me to select one Condition Type but not the Condition table?To the normal logic,it ought not to select Condition table but not the Condition Type!
    Dear all,I'm a new one in sd.May be this is a very stupid question.But it did puzzle me for a long time.If any one can  explain this question in detail and let me understand the concept,I will appreciate him/her very much.Thank you.

    Hi,
    You said that you are using the T.codes VK31 or VK32.
    These transaction codes are used to enter condition records for standard condition types. As you can see a grid left side having all the standard condition types like price, discounts, taxes, frieghts.
    Pl check using T.code VK11 OR VK12 (change mode)
    Here you can enter the required condition type, in the intial screen. (like PR00, MWST, K004, K005 .....etc)
    After giving the condition type, press enter or click on Combinations icon on top of the screen. Then you can see all the condition tables which you maintained for that condition type. Like as you said table 118, table 5, table 6 and table 4.
    You can select any table and press enter, then you can go into the screen in which you have all the field cataglogues you maintained for that table. For example you selected combination of Customer/Material (table 5) then after you press enter then you can see customer field on top, and material fields.
    You can give all the required values and save the conditon record.
    Hope this is clear.
    REWARD IF HELPFUL.
    Regards,
    praveen

  • 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.

  • 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.

  • 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,"

Maybe you are looking for