Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7692073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:46:08+00:00 2026-05-31T20:46:08+00:00

I’ve got a question about accomplishing something in regular expressions i.e is it possible

  • 0

I’ve got a question about accomplishing something in regular expressions i.e is it possible and if so how.

Short synopsis of what I am doing: I read Manga online. I like to open up the current issue in a new tab but I don’t always remember to click the link with a middle click.

So I decided to write a Greasemonkey script that would run on any of the sites pages adding a target="_blank" to any anchor tag that references a manga or an issue of that manga so a regular click would open it in a new tab. The script itself is working fine, nothing spectacular about it.

Now onto the caveat:

The link patterns we’ll call it for each Manga is as follows

    <language of manga>/<manga name> 
      links to the main about page for the manga

    <language of manga>/<manga name>/<issue number> 
      links to the issue number itself

    <language of manga>/<manga name>/<issue number>/<page number> 
      links to the specific page of the issue

Now I want it to always make the first two open in a new tab but I do NOT want the last one to open in a new tab. The reason for this is when reading the actual Manga each click to advance the page would open a new tab.

So to accomplish this I have two regular expressions:

    var MangaIssueRegex = /en-manga\/[A-Za-z0-9\-]+\//;
    var MangaIssuePageRegex = /en-manga\/[A-Za-z0-9\-]+\/(\d+\/){2}/

The first regex picks up any of the three manga link patterns.
The second regex picks up only the third manga link pattern (the one for a specific page)

In a nutshell the Greasemonkey script loops through all the anchor tags on the page when it loads and if the href attribute of the anchor tag passes the MangaIssueRegex AND fails the MangaIssuePageRegex the anchor tag is modified to open in a new tab otherwise the anchor tag is not modified.

Now is it possible to combine both regular expressions into a single one that will match the first two patterns but fail if the third pattern is encountered?

Here is the whole script:

    var MangaIssueRegex = /en-manga\/[A-Za-z0-9\-]+\//;
    var MangaIssuePageRegex = /en-manga\/[A-Za-z0-9\-]+\/(\d+\/){2}/
    var elements = document.getElementsByTagName("a");
    for (var i = 0; i < elements.length; i++)
    {
      if (MangaIssueRegex.test(elements[i].getAttribute("href")) && !MangaIssuePageRegex.test(elements[i].getAttribute("href")))
      {
        elements[i].setAttribute("target","_blank");
        elements[i].setAttribute("title","Opens in another tab");
      }
    }

Update

Thanks to both @DanielHilgarth and @iMoses for helping me figure this out

I found out I can use jQuery in Greasemonkey so in the end this is what I ended up with as the complete working script

$("a")
  .filter(function(){return /en-manga\/[\w\-]+\/(\d+\/)?$/.test(this.href);})
  .each(function(index){$(this).attr({title:"Opens in new tab",target:"_blank"});});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:46:09+00:00Added an answer on May 31, 2026 at 8:46 pm

    For matching only the first two patterns try using:

    var MangaIssuePageRegex = /en-manga\/[A-Za-z0-9\-]+\/(\d+\/)?$/
    

    This will match:

    <language of manga>/<manga name> 
    

    As well as:

    <language of manga>/<manga name>/<issue number> 
    

    If you don’t wish to enforce a closing backslash, use this Regex instead:

    var MangaIssuePageRegex = /en-manga\/[A-Za-z0-9\-]+(\/\d+)?(\/)?$/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.