Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Regular expressions

dmann200dmann200 Posts: 2Member
I am trying to split a string containing "filename.wav"

I tried the following

String[]stringArray = fileString.split(".")

and also

String[]stringArray = fileString.split(".")

Somehow I can't get JAVA to split it on the "." symbol because it is a reserved character in regular exressions. I read the page on regular expressions and couldn't find a way for it to recognize this character. I even tried it in octal and hex format...

Help!!


Comments

  • zibadianzibadian Posts: 6,349Member
    : I am trying to split a string containing "filename.wav"
    :
    : I tried the following
    :
    : String[]stringArray = fileString.split(".")
    :
    : and also
    :
    : String[]stringArray = fileString.split(".")
    :
    : Somehow I can't get JAVA to split it on the "." symbol because it is
    : a reserved character in regular exressions. I read the page on
    : regular expressions and couldn't find a way for it to recognize this
    : character. I even tried it in octal and hex format...
    :
    : Help!!
    :
    :
    :
    I've had a similar problem, and solved it using the regex character-selection group: []. Example:
    [code]
    split("[.]");
    [/code]
  • JonathanJonathan Posts: 2,914Member
    : I tried the following
    :
    : String[]stringArray = fileString.split(".")
    :
    : and also
    :
    : String[]stringArray = fileString.split(".")
    Thing is, I think Java itself is getting the and saying "ah, but there's nothing to escape with a ., so I just leave a literal . there". What you need, is for the to be passed along to the regex engine, so try escaping that.

    String[]stringArray = fileString.split("\.")

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
Sign In or Register to comment.