Results 1 to 5 of 5
  1. #1
    RR_QQ is offline Member
    Join Date
    Sep 2008
    Posts
    25
    Rep Power
    0

    Default Quick reg. expression help

    OK so I have a string that looks like this (mime):

    Java Code:
    text/plain; charset=UTF-8
    And I want to get rid of anything after the ";" so that I end up with just

    Java Code:
    text/plain
    Here is my code so far:
    Java Code:
    mimeType = mimeType.replaceAll(";*", "");
    However that code only gets rid of the ";" and nothing else giving me:

    Java Code:
    text/plain charset=UTF-8
    What am I doing wrong? I have this other codes that does work but I still want to know why my reg. expression is not working:

    Java Code:
    temp = mimeType.split(";");
    mimeType= temp[0];
    This code above is prob faster than a reg. ex? But I still need to learn reg. expressions! Thanks!

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    ";*" means any repetition of ';' such as ";;;;;;;;".

    i'm not very good with regex's as i somehow got through college without properly learning them, but i believe the correct regex would be ";.*" such that you have a semicolon followed by repetition of any character

    someone correct me if i'm wrong please

  3. #3
    RR_QQ is offline Member
    Join Date
    Sep 2008
    Posts
    25
    Rep Power
    0

    Default

    I think you are right...where in the world did I get that from. Ok the rule you gave seems to work. I guess I don't understand the "." part - does that mean "any character" ? Thanks!

  4. #4
    RR_QQ is offline Member
    Join Date
    Sep 2008
    Posts
    25
    Rep Power
    0

    Default

    And on that note...would just using the mimeType.split(";") and using the index 0 element be faster? I'm guessing it would be...

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Not really, or at least by a String of that length the difference would be so small as to be non-existent, regardless of which would be faster.

Similar Threads

  1. Need help quick!
    By Manikyr in forum New To Java
    Replies: 11
    Last Post: 01-28-2009, 04:08 AM
  2. One last quick question
    By jigglywiggly in forum New To Java
    Replies: 7
    Last Post: 01-26-2009, 08:53 AM
  3. Quick Question
    By Graeme in forum New To Java
    Replies: 4
    Last Post: 01-08-2009, 08:01 PM
  4. Quick Question
    By Spenc in forum New To Java
    Replies: 3
    Last Post: 09-22-2008, 02:26 PM
  5. Quick Help Please! Can't Run Code!!
    By VinceGuad in forum Eclipse
    Replies: 4
    Last Post: 01-16-2008, 03:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •