Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
regex wont work - bat pattern still right

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);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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:

  • Add a newline to the end of your string -- not the best option, unless you know your data will end up being formatted that way, which it might given that you're using the g and m modifiers.
  • Replace the \\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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!