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

200
Views
Regex – How to match everything outside brackets […] AND outside two exclamation marks with a pipe in-between !…|…!?

I was able to match everything outside the square brackets using ([^\[\]]+)(?:$|(?=\[)), which gives me:

!Bat_Boy.png|thumbnail! !visagepaume.png|thumbnail!, Test comment: public., Test comment: internal., [^TEST_ATTACHMENT.txt], Test comment: public!, !visagepaume.png|thumbnail!, Test comment: internal!, [^TEST_ATTACHMENT.txt]

Is there a way to write a single regex that would also match outside two exclamation marks with a pipe in-between, in addition? This is to be used with a single java string replaceAll() method. Basically, I am looking for this result:

!Bat_Boy.png|thumbnail! !visagepaume.png|thumbnail!, Test comment: public., Test comment: internal., [^TEST_ATTACHMENT.txt], Test comment: public!, !visagepaume.png|thumbnail!, Test comment: internal!, [^TEST_ATTACHMENT.txt]

Notes:

  • I am including the pipe in-between as a requirement mainly because there could be exclamation marks in those "test comments", and I thought maybe this would help.
  • Don't think I need to worry about nesting [] or !
about 4 years ago · Juan Pablo Isaza
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!