Regex help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tomerg3
    New Member
    • Dec 2006
    • 1

    #1

    Regex help

    Hi all,

    I'm trying to break a string at every , and .
    So I have something like Pattern.compile ("(\\. )|(, )");
    but this is not working well for me, I wanted to change it so it will match the "." only if it found only one in a given word
    Example:
    "Break here. But don't break he.re."
    So basically I want to know how to define a pattern that requires no more than 1 "." in a word.

    Thanks alot.
  • Colloid Snake
    New Member
    • Nov 2006
    • 144

    #2
    Originally posted by tomerg3
    Hi all,

    I'm trying to break a string at every , and .
    So I have something like Pattern.compile ("(\\. )|(, )");
    but this is not working well for me, I wanted to change it so it will match the "." only if it found only one in a given word
    Example:
    "Break here. But don't break he.re."
    So basically I want to know how to define a pattern that requires no more than 1 "." in a word.

    Thanks alot.
    Have you tried using the \s (indicates any whitespace) after the '.' or ','?

    Comment

    Working...