0

In javascript, I'm interested in splitting a body of text into an array sentences, where it ignores decimal numbers (and ideally web sites) for the split. I've found how to do it for sentences - e.g., str.split(/[\.\!]+\s*|\n+\s*/) - but not sure how to add the extra bit to ignore decimal numbers in the split

For example, if

str = "Hello there, the ice cream is $2.00.Toppings are extra."

Would result in

["Hello there, the ice cream is $2.00", "Toppings are extra"]

Is this possible?

thanks!

Paolo
  • 21,270
  • 6
  • 38
  • 69
user655489
  • 1,316
  • 3
  • 14
  • 21

2 Answers2

2
str = "Hello there, the ice cream is $2.00.Toppings are extra.";    
str.split(/[\.\!]+(?!\d)\s*|\n+\s*/); //[ 'Hello there, the ice cream is $2.00', 'Toppings are extra',]
  • (?!\d) Zero-width negative lookahead to match digit.

If the lookahead matches, The regex is not matched and the string is not splitted.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
0

Scala :

    import java.util.regex.Pattern;
    var regPattern = "(?<!\\d)\\.(?!\\d)|(?<=\\d)\\.(?!\\d)|(?<!\\d)\\.(?=\\d)";
    val pt = regPattern.compile(pattern);
    var strList: List[String]= pt.split(input).map(_.trim)(breakOut)
vaquar khan
  • 10,864
  • 5
  • 72
  • 96