Skip to content

Instantly share code, notes, and snippets.

@advorak
Last active September 27, 2016 17:51
Show Gist options
  • Save advorak/f58f92e88a5f0193c59c06958b6e0397 to your computer and use it in GitHub Desktop.
Save advorak/f58f92e88a5f0193c59c06958b6e0397 to your computer and use it in GitHub Desktop.
var data = `
OUT: 1111
OUT: andy
OUT: 121 OUT: 1324
NOTOUT: 1114
IN: 144`;
var values = [];
var pattern = //; /* Given the data above, suggest a regular expression to capture the lines containg "OUT: (a number)", also ignoring the lines NOTOUT and IN.. */
values = data.match(pattern);
/* The returned array is:
values == ["OUT: 1111", "OUT: 121", "OUT: 1324"]
*/
var data = `
OUT: 1111
OUT: andy
OUT: 121 OUT: 1324
NOTOUT: 1114
IN: 144`;
var values = [];
var pattern = /(\n|\s)OUT:\s+\d{3,4}/g; /* Given the data above, suggest a regular expression to capture the lines containg "OUT: (a number)", also ignoring the lines NOTOUT and IN.. */
values = data.match(pattern);
/* The returned array is:
values == [" OUT: 1111", " OUT: 121", " OUT: 1324"]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment