I'd like to divide the sentences into javascripts, but I'm asking because there's a limit to split.

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

Hello! I'm going to write a script in a long line text, and then write a program that divides one sentence by one so that it's

In other words, some special characters (.... *, !, ...) Etc.) I would like to divide long sentences starting with .

So I tried using split(), but in the case of split, the special character, which is the reference point, is deleted. Is there a way to leave a reference point without deleting it? Even if it's not a split, it's okay if you can divide each sentence as it is I can't find a keyword to search for, so it's hard to find another way ㅠ<

// I'm afraid it'll be ambiguous if I just express it in words...
Example sentence: Hello. Today... Have a good day?
The results you want: [Hello, today...] [Good day] [Have a good?]
If you used the code below: ["Hello", "Today", "Good Day", "Have You?"]
constscriptToChange=('Hello. Today... Have a nice day?') 

function scriptText(scriptToChange) {
  const result = scriptToChange.split(/\.+/g);
  return result;
}

console.log(scriptText(scriptToChange))

javascript

2022-09-20 10:50

1 Answers

I work as follows.

I use JavaScript from time to time, so I'm not sure if the grammar is correct.

vara = 'Go?Raganada! Ranada Ranada #RanadaRanadaRanadaRanadaRanadaRanada';
var b = ['?', '!', '#'];

b.forEach(function(e){
    a = a.replace(e, e + '@@@');
});
console.log(a)

var c = a.split('@@@')
console.log(c)

>> [email protected]@@[email protected]@@Ganadaradaradaradaradaradaradaradaradaradaradaradaradaradaradaradaradaradarada
["Gana?", "Ranada!", "Ganada Ranada #", "Ganada Ranada Ranada Ranada Ranada Ranada Ranada Ranada Ranada Ranada Ranada]


2022-09-20 10:50

If you have any answers or tips


© 2022 pinfo. All rights reserved.