Skip to content

Instantly share code, notes, and snippets.

@advorak advorak/1_regex-problem.js
Last active Sep 27, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.