Skip to main content
deleted 26 characters in body
Source Link
InSync
  • 8.6k
  • 4
  • 12
  • 42
  1. Design a regex that matches each particular element of the list rather then a list as a whole. Apply it with /g
  2. Iterate throught the matches, cleaning them from any garbage such as list separators that got mixed in. You may require another regex, or you can get by with simple replace substring method.

The sample code is in JS, sorry :) The idea must be clear enough.

    const string = 'HELLO,THERE,WORLD';

    // First use following regex matches each of the list items separately:
    const captureListElement = /^[^,]+|,\w+/g;
    const matches = string.match(captureListElement);

    // Some of the matches may include the separator, so we have to clean them:
    const cleanMatches = matches.map(match => match.replace(',',''));

    console.log(cleanMatches);
const string = 'HELLO,THERE,WORLD';

// First use following regex matches each of the list items separately:
const captureListElement = /^[^,]+|,\w+/g;
const matches = string.match(captureListElement);

// Some of the matches may include the separator, so we have to clean them:
const cleanMatches = matches.map(match => match.replace(',',''));

console.log(cleanMatches);
  1. Design a regex that matches each particular element of the list rather then a list as a whole. Apply it with /g
  2. Iterate throught the matches, cleaning them from any garbage such as list separators that got mixed in. You may require another regex, or you can get by with simple replace substring method.

The sample code is in JS, sorry :) The idea must be clear enough.

    const string = 'HELLO,THERE,WORLD';

    // First use following regex matches each of the list items separately:
    const captureListElement = /^[^,]+|,\w+/g;
    const matches = string.match(captureListElement);

    // Some of the matches may include the separator, so we have to clean them:
    const cleanMatches = matches.map(match => match.replace(',',''));

    console.log(cleanMatches);
  1. Design a regex that matches each particular element of the list rather then a list as a whole. Apply it with /g
  2. Iterate throught the matches, cleaning them from any garbage such as list separators that got mixed in. You may require another regex, or you can get by with simple replace substring method.

The sample code is in JS, sorry :) The idea must be clear enough.

const string = 'HELLO,THERE,WORLD';

// First use following regex matches each of the list items separately:
const captureListElement = /^[^,]+|,\w+/g;
const matches = string.match(captureListElement);

// Some of the matches may include the separator, so we have to clean them:
const cleanMatches = matches.map(match => match.replace(',',''));

console.log(cleanMatches);
added 69 characters in body
Source Link
  1. Design a regex that matches each particular element of the list rather then a list as a whole. Apply it with /g
  2. Iterate throught the matches, cleaning them from any garbage such as list separators that got mixed in. You may require another regex, or you can get by with simple replace substring method.

The sample code is in JS, sorry :) The idea must be clear enough.

    const string = 'HELLO,THERE,WORLD';

    // First use following regex matches each of the list items separately:
    const captureListElement = /^[^,]+|,\w+/g;
    const matches = string.match(captureListElement);

    // Some of the matches may include the separator, so we have to clean them:
    const cleanMatches = matches.map(match => match.replace(',',''));

    console.log(cleanMatches);
  1. Design a regex that matches each particular element of the list rather then a list as a whole. Apply it with /g
  2. Iterate throught the matches, cleaning them from any garbage such as list separators that got mixed in. You may require another regex, or you can get by with simple replace substring method.
    const string = 'HELLO,THERE,WORLD';

    // First use following regex matches each of the list items separately:
    const captureListElement = /^[^,]+|,\w+/g;
    const matches = string.match(captureListElement);

    // Some of the matches may include the separator, so we have to clean them:
    const cleanMatches = matches.map(match => match.replace(',',''));

    console.log(cleanMatches);
  1. Design a regex that matches each particular element of the list rather then a list as a whole. Apply it with /g
  2. Iterate throught the matches, cleaning them from any garbage such as list separators that got mixed in. You may require another regex, or you can get by with simple replace substring method.

The sample code is in JS, sorry :) The idea must be clear enough.

    const string = 'HELLO,THERE,WORLD';

    // First use following regex matches each of the list items separately:
    const captureListElement = /^[^,]+|,\w+/g;
    const matches = string.match(captureListElement);

    // Some of the matches may include the separator, so we have to clean them:
    const cleanMatches = matches.map(match => match.replace(',',''));

    console.log(cleanMatches);
Source Link

  1. Design a regex that matches each particular element of the list rather then a list as a whole. Apply it with /g
  2. Iterate throught the matches, cleaning them from any garbage such as list separators that got mixed in. You may require another regex, or you can get by with simple replace substring method.
    const string = 'HELLO,THERE,WORLD';

    // First use following regex matches each of the list items separately:
    const captureListElement = /^[^,]+|,\w+/g;
    const matches = string.match(captureListElement);

    // Some of the matches may include the separator, so we have to clean them:
    const cleanMatches = matches.map(match => match.replace(',',''));

    console.log(cleanMatches);