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 8125215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:44:35+00:00 2026-06-06T06:44:35+00:00

Ok, a friend of mine confronted me with a regular expression he found in

  • 0

Ok, a friend of mine confronted me with a regular expression he found in a piece of code and I am not experienced at all. I tried to figure it out and I really think that it is quite basic, but I have trouble.

The expression is: ^(.*?){0,1}>$

So this is what I gathered from various tutorials and definitions:

  • ^ stands for “start” and $ for end, so expression between those must describe the full string in order to be selected.
  • *? is a lazy operator (meaning it first tries to take 0 of the preceeding character, if that doesn’t match, it takes one, two, three, etc).
  • (.*?) so this must mean “takes as few characters as possible”.
  • (.*?){0,1}: Now the trouble beginns for me. “Take as few characters as possible, zero times or once”?
  • ^(.*?){0,1}>$: “Take as few characters as possible, zero times or once, with the character > afterwards followed by the end”?

That would basically mean “select everything, if a > is at the end of the string”? I am confused… I would appreciate it if someone could shed some light on this (I guess very basic) problem…

EDIT: Ok, to prevent missunderstanding, the regex is used in this context:

.replace(/^(.*?){0,1}>$/,"$1/>");
  • 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-06T06:44:37+00:00Added an answer on June 6, 2026 at 6:44 am

    What you have is equivalent to the following:

    ^(.*)>$
    

    Whoever wrote it in the first place was probably in a hurry, and didn’t realize they were putting so much extraneous stuff in there.


    After clarifying your use case, just use this:

    .replace(/>$/, '/>');
    

    and it’ll add a slash before the closing > tag (if there is one).


    If you want to add the slash only if it’s not there yet, use this:

    .replace(/([^\/])>$/, '$1/>');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A friend of mine sent me this code snippet to celebrate his new baby
A friend of mine said that they experienced oddities with using the decimal column
A friend of mine wanted help learning to program, so he gave me all
A friend of mine is getting this error on ALL of her websites. They
A friend of mine really likes using Joomla as a base for his websites.
A friend of mine got bitten by the all too famous 'anonymous functions in
a friend of mine gave me a piece of his software and I'm trying
A friend of mine discovered some interesting behaviour in some Javascript code, which I
A friend of mine wants me to convert his code into a doubly linked
A friend of mine wants to hand out CDs (yes, compact disks) as invitations

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.