0

I'm working with the following file addresses format:

/A/B/C/D/foo/bar

I want to come up with a regular expression in Matlab that will return the last word in the adress. In this case I want the word "bar". What would be the regular expression?

1 Answer 1

2

If you're just trying to get the file name from the full file path, you can use fileparts rather than a regex:

>> [path,name,ext] = fileparts('/A/B/C/D/foo/bar')
path = /A/B/C/D/foo
name = bar
ext =

If bar has an extension, then it would be:

>> [path,name,ext] = fileparts('/A/B/C/D/foo/bar.txt')
path = /A/B/C/D/foo
name = bar
ext = .txt
>> nameext = [name ext]
nameext = bar.txt
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.