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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:12:26+00:00 2026-05-23T03:12:26+00:00

I have a problem with matching text in Vim buffers. I have a specific

  • 0

I have a problem with matching text in Vim buffers. I have a specific form of dates in my text and often need to test whether the text at cursor matches the date pattern.

Here are some examples of the formatted dates, which may be preceded or followed by other text on the same line:

<2011-10-13 Wed>
[2011-10-13 Wed]
<2011-10-13 Wed +1>
[2011-10-13 Wed +1]
<2011-10-13 Wed 10:30>
[2011-10-13 Wed 10:30]
<2011-10-13 Wed 10:30-11:30>
[2011-10-13 Wed 10:30-11:30]
<2011-10-13 Wed 10:30 +1w>
[2011-10-13 Wed 10:30 +1w]

I have some code that tests at cursor position to see whether cursor is on a date, and if so what the date text is, but what I’m doing seems kind of clumsy.

Any comments on what most efficient function for returning the date under cursor (or empty string if not on a date)? (I would post my code but will refrain for now both (1) out of embarrassment and (2) to avoid polluting your minds by suggesting a particular approach to the problem.)

Thanks for any tips.

  • 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-23T03:12:27+00:00Added an answer on May 23, 2026 at 3:12 am
    function! CheckDate(expr)
        let date_pattern = '[\[<]'      " The first < or [
                    \.'\d\{4\}-\d\{2\}-\d\{2\}' " YYYY-MM-DD
                    \.' \(Mon\|Tue\|Wed\|Thu\|Fri\|Sat\|Sun\)' " Week day
                    \.'\( \d\{2\}:\d\{2\}\(-\d\{2\}:\d\{2\}\)\?\)\?'
                                        " Optional time or range
                    \.'\( +\dw\?\)\?'   " Optional + digit with optional 'w'
                    \.'\([\]>]\)'     " The closing > or ]
        return match(a:expr, date_pattern) != -1
    endfunction
    
    function! IsOverDate()
        call setreg('a','')
        call setreg('b','')
        normal! "aya>
        let expr1 = getreg('a')
        normal! "bya]
        let expr2 = getreg('b')
        if CheckDate(expr1)
            return expr1
        elseif CheckDate(expr2)
            return expr2
        endif
        return ''
    endfunction
    

    The function IsOverDate() clears the registers a and b and stores in the respective registers the text under the cursor which is inside < and > and < and >, including the brackets. Then, it gets the value from the registers a and b and sends it to the function CheckDate() which checks if the expression matches the date pattern (I have based myself in your samples and made some assumptions to build the pattern).

    The CheckDate() function returns true only if the expression matches the date pattern. The function IsOverDate() returns the date under the cursor (with the brackets) or an empty string if the cursor is not over a date.

    I hope it suits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm matching identifiers, but now I have a problem: my identifiers are allowed to
I have problem when I try insert some data to Informix TEXT column via
I am having a problem with matching elements in jQuery. Basically I have list
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I do not have problem as such but I am quite new to Ruby.
I have a problem using the Java search function in Eclipse on a particular

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.