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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:32:14+00:00 2026-05-31T16:32:14+00:00

POSIX Expression is giving me a headache. Lets say we have a string: a

  • 0

POSIX Expression is giving me a headache.

Lets say we have a string:

a = "[question(37), question_pipe(\"Person10\")]"

and ultimately I would like to be able to have:

b = c("37", "Person10")

I’ve had a look at the stringr package but cant figure out how to extract the information out using regular expressions and str_split.

Any help would be greatly appreciated.

Cameron

  • 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-31T16:32:15+00:00Added an answer on May 31, 2026 at 4:32 pm

    So if I understand correctly you want to extract the elements within parenthesis.

    You can first extract those elements, including the parenthesis, using str_extract_all:

    b1 <- str_extract_all(string = a, pattern = "\\(.*?\\)")
    b1
    # [[1]]
    # [1] "(37)"           "(\"Person10\")"
    

    Since str_extract_all returns a list, let’s turn it into a vector:

    b2 <- unlist(b1)
    b2
    # [1] "(37)"           "(\"Person10\")"
    

    Last, you can remove the parenthesis (the first and last character of each string) using str_sub:

    b3 <- str_sub(string = b2, start = 2L, end = -2L) 
    b3
    # [1] "37"           "\"Person10\""
    

    Edit: A few comments about the regex pattern: \\( and \\) are your opening and closing parenthesis. .*? means any character string but without being greedy, otherwise you would get one long match from the first ( to the last ).

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

Sidebar

Related Questions

I have POSIX in mind for implementation, though this question is more about architecture.
Using POSIX threads & C++, I have an Insert operation which can only be
I need to parse a string like func1(arg1, arg2); func2(arg3, arg4); . It's not
Posix provided both named and non-named pipes... Can you have a non-named pipes and
What exactly is POSIX? I have read the Wikipedia article but I still don't
Since POSIX regular expressions (ereg) are deprecated since PHP 5.3.0, I'd like to know
On posix it is possible to use timespec to calculate accurate time length (like
The POSIX system call putenv states that the allocated memory string cannot be freed
How to extract only DATABASE_NAME from this string using POSIX-style regular expressions? st <-
I have the simple regular expression: \{[0-9]*\} which works fine with PHP's ereg_ functions

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.