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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:55:13+00:00 2026-06-14T16:55:13+00:00

I have a vector of strings: s <- c(‘abc1’, ‘abc2’, ‘abc3’, ‘abc11’, ‘abc12’, ‘abcde1’,

  • 0

I have a vector of strings:

s <- c('abc1',   'abc2',   'abc3',   'abc11',   'abc12', 
       'abcde1', 'abcde2', 'abcde3', 'abcde11', 'abcde12', 
       'nonsense')

I would like a regular expression to match only the strings that begin with abc and end with 3, 11, or 12. In other words, the regex has to exclude abc1 but not abc11, abc2 but not abc12, and so on.

I thought that this would be easy to do with lookahead assertions, but I haven’t found a way. Is there one?


EDIT: Thanks to posters below for pointing out a serious ambiguity in the original post.

In reality, I have many strings. They all end in digits: some in 0, some in 9, some in the digits in between. I am looking for a regex that will match all strings except those that end with a letter followed by a 1 or a 2. (The regex should also match only those strings that start with abc, but that’s an easy problem.)

I tried to use negative lookahead assertions to create such a regex. But I didn’t have any success.


Thanks to all who replied and commented. Inspired by several of you, I ended up using this combination: grepl('^abc', s) & !grepl('[[:lower:]][12]$', s).

  • 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-14T16:55:14+00:00Added an answer on June 14, 2026 at 4:55 pm

    Instead of one complicated regular expression, in this case I think it’s easier to use two simple regular expressions:

    s <- c('abc1',   'abc2',   'abc3',   'abc11',   'abc12', 
           'abcde1', 'abcde2', 'abcde3', 'abcde11', 'abcde12', 
           'nonsense')
    
    s[grepl("^abc", s) & grepl("(3|11|12)$", s)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector of strings which are changing its contents for no apparent
I have a std::vector<uint8_t> that contains strings at specific offsets. Here's a shortened dump:
I have some data structures: all_unordered_m is a big vector containing all the strings
I have vector of strings and want to create a fixed with string out
A have a vector of strings in c++: vector<string> myVect = {A, A, A,
I have a vector of strings: std::vector<std::string> fName which holds a list of file
I have a vector of strings. Check out my vector, it's awesome : >
Let's just say i have a Vector of Strings, and I want to output
I have a vector of strings im working trought, and i need to check
If I have a vector of strings how do I do a binary search

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.