Regular expressions - Programmers Heaven

Howdy, Stranger!

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

Categories

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.