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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:22:11+00:00 2026-06-17T18:22:11+00:00

I have a path like this ../some/thing/foobar/foobar.happening and I want the character string between

  • 0

I have a path like this ../some/thing/foobar/foobar.happening and I want the character string between the last / and ..

I realize this will be easy for some, but I’m not yet familiar with regular expressions etc.
I also probably could do this by myself with strsplit, but I’m looking for an elegant one-liner, if possible.

Thanks in advance!

  • 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-17T18:22:12+00:00Added an answer on June 17, 2026 at 6:22 pm

    basename will give you the part after the last slash. Then, you can split on the dot (which you have to escape with two \)

    > (name <- basename("../some/thing/foobar/foobar.happening"))
    [1] "foobar.happening"
    > unlist(strsplit(name, "\\."))
    [1] "foobar"    "happening"
    

    Then select the first element

    > unlist(strsplit(name, "\\."))[1]
    [1] "foobar"
    

    I see you actually asked for a way other than strsplit. Here’s a regular expression

    > sub(".*/([^/]+)\\..*", "\\1", "../some/thing/foobar/foobar.happening")
    [1] "foobar"
    
    • It looks for zero or more occurences of anything .*
    • followed by a forward slash /
    • followed by anything that is not a forward slash [^/] (inside the brackets, ^ means “not”), one or more times +.
    • followed by a dot \\.
    • followed by anything zero or more times .*.

    Then it replaces that with only the stuff inside the parenthesis [^/]+ which is everything between the forward slash and the dot. The \\1 means the stuff inside the first set of parenthesis. (there’s only one set in this case, but if there were a second we could refer to it with \\2)

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

Sidebar

Related Questions

I have an array of file path components like this: [ ['some', 'dir', 'file.txt'],
I have stored the XML path to items in a string like this: response->items->item
Let's say I have some code like this in AS3 for(...) thing = new
Noticed a strange thing today. I have some code like this in a project
I have a path like this: parent/child/reply How do I use PHP to remove
I have a path like C:\application\photo\gallery\sketches . Now I need to check whether this
I have a class this is annotated with @Path like so: @Path(widgets) @Produces(MediaType.APPLICATION_XML) public
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
I have stored images from the net like this Documents/imagecache/domain1/original/path/inURI/foo.png Documents/imagecache/domain2/original/path/inURI/bar.png Documents/imagecache/... Documents/imagecache/... Now
let's say i have directory paths looking like this: this/is/the/basedir/path/a/include this/is/the/basedir/path/b/include this/is/the/basedir/path/a this/is/the/basedir/path/b In

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.