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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:53:33+00:00 2026-06-14T08:53:33+00:00

New to regex and I need to pattern match on some dates to change

  • 0

New to regex and I need to pattern match on some dates to change the format.

I’m going from mm/dd/yy to yyyy-mm-dd where there are no entries prior to 2000.

What I’m unfamiliar with is how to group things to use their respective references of \1, \2, etc.

Would I first want to match on mm/dd/yy with something like ( \d{2} ) ( \/\d{2} ) ( \/\d{2} ) or is it as easy as \d\d/\d\d/\d\d ?

Assuming my first grouping is partially the right idea, I’m looking to do something like:

:%s/old/new/g
:%s/ ( \d{2} ) ( \/\d{2} ) ( \/\d{2} ) / ( 20+\3) - (\3) - (\1) /g

EDIT: Sorry, the replace is going to a yyyy-mm-dd format with hyphens, not the slash.

  • 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-14T08:53:34+00:00Added an answer on June 14, 2026 at 8:53 am

    I was going to comment on another answer but it got complicated.

    Mind the magic setting. If you want unescaped parens to do grouping, you need to include \v somewhere in your pattern. (See :help magic).

    You can avoid escaping the slashes if you use something other than slashes in the :s command.

    You are close. 🙂 You don’t want all of those spaces though as they’ll require spaces in the same places to match.

    My solution, where I use \v so I don’t need to escape the parens and exclamation points so I can use slashes in my pattern without escaping them:

    :%s!\v(\d{2})/(\d{2})/(\d{2})!20\3-\2-\1!g
    

    This will match “inside” items that start or end with three or more digits though, too. If you can give begin/end criteria then that’d possibly be helpful. Assuming that simple “word boundary” conditions work, you can use <>:

    :%s!\v<(\d{2})/(\d{2})/(\d{2})>!20\3-\2-\1!g
    

    To critique yours specifically (for learning!):

    :%s/ ( \d{2} ) ( \/\d{2} ) ( \/\d{2} ) / ( 20+\3) - (\3) - (\1) /g
    
    • Get rid of the spaces since presumably you don’t want them!
    • Your grouping needs either \( \) or \v to work
    • You also need \{2} unless you use \v
    • You are putting the slashes in groups two and three which means they’ll show up in the replacement too
    • You don’t want the parentheses in the output!
    • You’re substituting text directly; you don’t want the + after the 20 in the output
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Regex .I want to match pattern of my file ..
I need a RegEx pattern which matches from where to the end of the
Here's what I need- RegEx to match a url pattern and rewrite it to
Im totally new to regex. I need your help. What is the regex function
New to Regex. I want to validate to this format: Any character allowed, except
I lack experience with regex and I need some help. I need to extract
I'm fairly new to C# programming and need some help. I am trying to
I need to match certain things from lines of an input text. The lines
I have some regex code originally written in PHP and I need to port
I found following pattern from RegexLibrary , and i don't know how use Match

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.