0

I have a string of the following form:

No Status: not enough information to provide one. more research and data-gathering is required.

I am trying to remove everything after the ':' up to the first space after the '.', so that the result would be like the following:

 No Status: more research and data-gathering is required.

Is there any regex that I can use to achieve this in JavaScript?

Dharman
  • 30,962
  • 25
  • 85
  • 135
ceno980
  • 2,003
  • 1
  • 19
  • 37
  • Use split twice, first by ```":"``` and then by ```"."```. – sibasishm Oct 25 '19 at 09:32
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/a/2759417/3832970) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Oct 25 '19 at 09:32
  • Ironic, answer to your question should be "_more research and data-gathering is required_" – Justinas Jun 14 '23 at 08:40

1 Answers1

1

You don't need regex for simple string replacement:

let myString = 'No Status: not enough information to provide one. more research and data-gathering is required.';

let newString = myString.replace('not enough information to provide one. ', '');

console.log(newString);

or with regex:

let myString = 'No Status: not enough information to provide one. more research and data-gathering is required.';

let newString = myString.replace(/:.*?\./, ':');

console.log(newString);
Justinas
  • 41,402
  • 5
  • 66
  • 96