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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:20:49+00:00 2026-05-24T00:20:49+00:00

Is it possible to use stored variables in R’s regex? For example I want

  • 0

Is it possible to use stored variables in R’s regex?

For example I want to remove quotes around decimal numbers in the following string s = "\"Bob\",\"1\",\"Mary\",\"2\"" – in most languages you could do something like sub("\"(\d)\"","$1",s) but I cannot seem to find the capability in R. Any help would be greatly appreciated.

Also as a side question does R have the \d support? (it throws an error when i try it) Thanks

  • 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-24T00:20:49+00:00Added an answer on May 24, 2026 at 12:20 am

    I believe this is usually called back referencing. In R, you can use \\1 \\2, etc.

    re.examples <- c(
        'What_are_we_doing?',
        'Woe, that a young fowl should fly the coop',
        '2011/12/24',
        'Subject: More information, then less important stuff.' 
    )
    
    sub("([0-9]+)/([0-9]+)/([0-9]+)","Year is \\1 Month is \\2 Day is \\3",re.examples[3])
    sub("^([A-Za-z ]+): ([A-Za-z ]+), ([A-Za-z ]+).$","\\2",re.examples[4])
    

    I’m not sure about \d support in R. I generally just use [0-9] anyway, since I know it works and I find it easier to read.

    Edit: @Andrie and @Richie Cotton both offered two suggestions in comments, which I will include here for completeness. [:digits:] works, but to my mind offers little in readability over [0-9]. \\d works as well.

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

Sidebar

Related Questions

I want to use table variables in stored procedures but here is an issue.
I want to use PHP to check, if string stored in $myoutput variable contains
2 Questions actually: I know i must use Stored Procedures as much as Possible,
I simply want to execute a MySQL stored procedure. But I want to use
I have the following two variables: a = 1; b = 'a'; I want
Heyo, Odd question... is it possible/ ok. To use a combination of SESSION variables
Is it possible to store the credentials that I use to connect to my
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
I have recently started looking into Google Charts API for possible use within the
Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through 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.