Показать сообщение отдельно
  #1 (permalink)  
Старый 16.02.2018, 12:05
Новичок на форуме
Отправить личное сообщение для yarm Посмотреть профиль Найти все сообщения от yarm
 
Регистрация: 16.02.2018
Сообщений: 2

Поиск по файлу с использованием регулярного выражения
Здравствуйте.
Возможно глупый вопрос, но если есть кто-то умный и опытный, подскажите, как реализовать поиск в файле с помощью регулярного выражения.
по заданию:
The definition of the settlement due date will always be in the body of text following the heading “Settlement Due Date” and can be expressed as (i) a date with the day, month and year in a variety of formats, e.g. number before or after the name of the month, with or without “st”, “nd”, “rd”, “th” superscripts like, e.g. 1st and 1 are both valid BUT not in US format – so 1/31/2018 is not a valid date; or (ii) as a number of days, e.g. “30 days” “thirty days”, where the number of days may only be 30, 45, 60, or 90.

Регулярку напишу сама, сейчас пытаюсь понять, почему я не могу найти в файле хедеры “Settlement Due Date”

const fs = require('fs');
const readeble = process.argv[2];
const reg = /Settlement Due Date:/g;

fs.readFile(readeble, function (err, data) {
if (err) {
console.log('Error!!!');
}
const res = data.toString();

if (res.match(reg)) {
console.log(res.search(reg));
}

});

У меня возвращается число 776...
Ответить с цитированием