-1

I want to be able to regex multiple sentences from one regex if it is possible

/(.*)<FooBar>/s 

this only matches one word (I think) I need something that matches words follows by spaces.

this is the regex that I tried but does not seem to work I don't know if it's because of javascript syntax or something else. (I'm new to regex)

^.*(EVENTS\:OB\:\sRECORDS\snot|EVENTS\:OB\:\sRECORDS\sthat|EVENTS\:OB\:\sUnprocessed).(?<!0\.0)$

Uncaught SyntaxError: Unexpected token ^

these are examples of sentences that I want to regex

EVENTS:OB: Records not updated to status
EVENTS:OB: Records that were pending OR to be processed for yester day.  
EVENTS:OB: Unprocessed records older than hour.  
RENAS:OB:BOX: Unprocessed records older than hour.  
RENAS:MOSS Pending  
RENAS:TIGNET Pending  
RENAS:OB:SI: Unprocessed records older than hour.  
RENAS:OB:GC: Unprocessed records older than hour.  
RENAS:RENAS:Count of pending message to process. 
RENAS:OB:10+2_Status: Unprocessed records older than hour.
RENAS:RENAS_10+2:Unprocessed records in RENAS 10+2
RENAS:RENAS ACH:Count of pending message to process to FV.
RENAS:CheckNow:Count of pending message to process to FV
RENAS:OB:GB: Unprocessed records older than hour.
RENAS:RENAS: UN Processed records by MIXX for RENAS INSTRUCTONS 
RENAS:RENAS: UN Processed records by MIXX for RENAS Break Bulk 
RENAS:RENAS: UN Processed records by MIXX for RENAS 
RENAS:OB:DOM:Unprocessed count of records older than hour.
RENAS:OB:DOM:Failed records in the database for previous date.
RENAS:OB:SI:Records that were pending to be processed for the previous day.

what I have been doing is this

function getLines(text) {
  var lines = [];
  var re = /^.*(EVENTS\:OB\:\sRECORDS\snot|EVENTS\:OB\:\sRECORDS\sthat|EVENTS\:OB\:\sUnprocessed).(?<!0\.0)$/;
  while (m = re.exec(text)) {
    lines.push(m[1]);
  };

  return lines;
}

$(function() {
    $('#printlogs').html(getLines($('textarea').val()).join('<br>'));
});
learningbyexample
  • 1,527
  • 2
  • 21
  • 42
  • 2
    Possible duplicate of [How do I match any character across multiple lines in a regular expression?](https://stackoverflow.com/questions/159118/how-do-i-match-any-character-across-multiple-lines-in-a-regular-expression) – Spencer Wieczorek Sep 06 '17 at 14:10
  • `/(.*)/s` can match more than one word. Your first regex fails because you're trying to use a negative lookbehind `(?<!...)` while lookbehinds aren't implemented in Javascript. The lookbehind doesn't make sense anyway : it's impossible to have just matched `0.0` when you actually just matched a single character after one of the strings of your alternation, none of which end in `0.`. – Aaron Sep 06 '17 at 14:55
  • still doesn't work keeps giving me **Uncaught SyntaxError: Unexpected token ^** – learningbyexample Sep 06 '17 at 14:58
  • did you enclose your regex in `/.../` or use the `Pattern` constructor with a string parameter? Outside of these contexts (and a few others where it has other meanings), the `^` symbol would raise a SyntaxError – Aaron Sep 06 '17 at 15:01
  • I'm new to regex so I don't know syntax for javasript and what it allows. – learningbyexample Sep 06 '17 at 15:04
  • [Here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)'s MDN article on Regular Expressions in Javascript, it's a quality article whose reading will probably save you some time by the future. – Aaron Sep 06 '17 at 15:12
  • BTW the snippet of javascript looks alright, with a regex that seems to satisfy the need you express by the start of your question. I'm still totally confused as to what you mean by the last two paragraphs of your question though. – Aaron Sep 06 '17 at 15:16
  • they were for reference but I just deleted them. either way it's still not working with the /.../ – learningbyexample Sep 06 '17 at 15:31
  • 2
    Please provide an example of exactly what kinds of matches you would want as a result of the example input you supplied. – BoffinBrain Sep 06 '17 at 16:09
  • Try [this one](https://regex101.com/r/1mJ0Eg/2), `/^.*(?:EVENTS:OB:\s(?:RECORDS\snot|RECORDS\sthat|Unprocessed))(?!.*0\.0$).*$/gim` – Wiktor Stribiżew Sep 06 '17 at 16:39
  • @WiktorStribiżew this regex does not seem to work with javascrpit or i dont know if im imputing it wrong **var re = /^.*(?:EVENTS:OB:\s(?:RECORDS\snot|RECORDS\sthat|Unprocessed‌​))(?!.*0\.0$).*$/gim;** – learningbyexample Sep 06 '17 at 17:40
  • Did you copy it from the comment? Don't. Copy it from the https://regex101.com/r/1mJ0Eg/2 fiddle. SO inserts rubbish into comments to make them look better. – Wiktor Stribiżew Sep 06 '17 at 17:42
  • @WiktorStribiżew the line that I have is exactly as I pasted in my previous comment with my var re variable in code it's `var re = /^.*(?:EVENTS:OB:\s(?:RECORDS\snot|RECORDS\sthat|Unprocessed‌​‌​))(?!.*0\.0$).*$/g‌​im;` – learningbyexample Sep 06 '17 at 18:05
  • Let's talk code: see https://jsfiddle.net/y8dahg1u/ - are the results expected? – Wiktor Stribiżew Sep 06 '17 at 19:06

1 Answers1

0

You need a negative lookahead instead of a non-supported lookbehind:

/^.*(?:EVENTS:OB:\s(?:RECORDS\snot|RECORDS\sthat|Unprocessed))(?!.*0\.0$).*$/gim

See the regex demo.

Details

  • ^ - start of string
  • .* - any 0+ chars other than line break chars, as many as possible
  • (?:EVENTS:OB:\s(?:RECORDS\snot|RECORDS\sthat|Unprocessed)) - a EVENTS:OB: string followed with 1 whitespace and any of the alternatives:
    • RECORDS\snot - RECORDS, a whitespace, not
    • RECORDS\sthat - RECORDS, a whitespace, that
    • Unprocessed - an Unprocessed substring
  • (?!.*0\.0$) - there can't be a 0.0 at the end of the line
  • .*$ - any 0+ chars other than line break chars, as many as possible, up to the end of the line.

var s = "EVENTS:OB: Records not updated to status\nEVENTS:OB: Records that were pending OR to be processed for yester day.  \nEVENTS:OB: Unprocessed records older than hour.  \nRENAS:OB:BOX: Unprocessed records older than hour.  \nRENAS:MOSS Pending  \nRENAS:TIGNET Pending  \nRENAS:OB:SI: Unprocessed records older than hour.  \nRENAS:OB:GC: Unprocessed records older than hour.  \nRENAS:RENAS:Count of pending message to process. \nRENAS:OB:10+2_Status: Unprocessed records older than hour.\nRENAS:RENAS_10+2:Unprocessed records in RENAS 10+2\nRENAS:RENAS ACH:Count of pending message to process to FV.\nRENAS:CheckNow:Count of pending message to process to FV\nRENAS:OB:GB: Unprocessed records older than hour.\nRENAS:RENAS: UN Processed records by MIXX for RENAS INSTRUCTONS \nRENAS:RENAS: UN Processed records by MIXX for RENAS Break Bulk \nRENAS:RENAS: UN Processed records by MIXX for RENAS \nRENAS:OB:DOM:Unprocessed count of records older than hour.\nRENAS:OB:DOM:Failed records in the database for previous date.\nRENAS:OB:SI:Records that were pending to be processed for the previous day.";
var re = /^.*(?:EVENTS:OB:\s(?:RECORDS\snot|RECORDS\sthat|Unprocessed))(?!.*0\.0$).*$/gim;
document.body.innerHTML = "<pre>" + JSON.stringify(s.match(re), 0, 4) + "</pre>";
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563