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

  • SEARCH
  • Home
  • 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 8834817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:06:51+00:00 2026-06-14T09:06:51+00:00

I have a regular expression I am trying to use to rewrite an incoming

  • 0

I have a regular expression I am trying to use to rewrite an incoming REST url and am getting stuck on one use case when one section of the URL is excluded.

Here is the regex I’m currently using:

^(/[^/]+/(?:books))/([^/]+?)(?:/(?:(?!page).+?))?(?:/page/(\\d+))?$

As example I’m using “$1 – $2 – $3” as parts to use in writing new URL.

Here are the examples that are working correctly…

"/mySite/books/topic1/page/2" results in "/mySite/books - topic1 - 2"
"/mySite/books/topic1/subtopic1/page/2" results in "/mySite/books - topic1 - 2"

All the above work as intended. The problem is when the URL excludes the “topic1” part of the URL then the results are not what I need. Example:

"/mySite/books/page/2" results in "/mySite/books - page - "

What I need is the $2 to be blank, because there is no topic, and the page number still as $3. What I need as output…

"/mySite/books/page/2" results in "/mySite/books -  - 2"

What can I change in my regex to satisfy that scenario without disrupting the existing ones that work correctly? This is being done in Java.

  • 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-06-14T09:06:52+00:00Added an answer on June 14, 2026 at 9:06 am

    You might try to use regex pattern

    ^(/[^/]+/books)/(?:(?!page/)([^/]+)/)?page/(\\d+)$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a regular expression to use to validate a url path.
I have been trying to use Regular Expression to separate full sentences in a
I have the following regular expression: ^[-+]?[\d{0,3},?\d{3}]*\.?\d+$ I am trying to support numbers of
I'm trying to validate mm-dd-(2012~2099) date format. I have the following regular expression. ^(0[1-9]|1[0-2])-(0[1-9]|[10-31])-(20[12-99])$
I am trying to fix a regular expression i have been using in php
I am trying to use regular expression to search a document fo a UUID
I am trying to use a regular expression and it's just breaking my brain.
I am having problems trying to use the regular expression that I used in
I have an issue regarding the use of the following regular expression: private Regex
I have a regular expression for use with awk to find any of the

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.