my regex are not working. I cant understand Why.
let text = '0x00d38f0ff55cf1b18841a7e7993eb5b1df791f7be40a828b94e6df90dafd9d722021-11-28 23:08:3918 hrs 5 mins ago0xba4090fb813a5da6c24d53149d98d8539e2469caOUT PancakeSwap V2: HTD-BUSD 1445.871849548172161305 HeroesTD (HTD)';
let regex = new RegExp("(.*?)2021(.*?)ago(.*?)(IN|OUT)(.*?)\\s(.*?)\\s\^", "gm");
let result;
result = regex.exec(text);
console.log(result);
The \^ ends up matching the beginning of a line (since you're using the m modifier). Your string is has no newline characters in it, so its not possible to match that string with what you have right now.
The possible solutions I can think of are:
\\s\^ with a $, since that matches the end of a line regardless of whether or not another line comes after it -- probably the better, cleaner option.Edit:
For clarification, since you explicitly asked why it doesn't seem to be matching like you want. Your regex does match all the way up to the last \s you have, but fails at the ^. There seems to be a lot of assumptions about what you want to match, and so the solution will vary accordingly. Yes, you could just remove the \^ like others have suggested, but that would no longer match the whole line, stopping just at "PancakeSwap" which I can only assume is not what you want? Another way to "fix" this would be to remove the \s\^ from the end of that string, and take that final (.*?) and make it greedy: (.*). This "greediness" just means it will try to match as much as it can (for the most part), so removing the \s^ will allow it to match all the way to the end of the line -- although this could backfire if there ends up being more lines after this. Again, I can only assume that you intend to match all the way to the end of the line, since that's what \s^ is doing -- although its only doing that in the presence of another line proceeding it.