regexp - remove all until first slash

Peter Ostry's icon

[regexp] input:Avocado:/folder/folder/folder/...Ford:/folder/folder/folder/...SteveMcQueen:/folder/folder/folder/...

[regexp] output:
/folder/folder/folder/...

How to remove everything up to the first slash?

I am a RegEx dummy but I guess for some of you it's just a quickie.

Ernest's icon

Be consoled. There is no such thing as a quickie in regular expressions.

There are two approaches to removing characters from the beginning of a string. The intuitive approach is to build a ,atch for the characters one wants to remove and substitute them with empty space. The second and better is to match from the end of the string. The second is better because the match is then available for back reference if you later want to extend the expression and add something more to the wanted match. So if you instead identify a leading marker in the part you want to keep and match backwards to that, you are likely to be better off in the future.

Peter Ostry's icon

Oops, I thought that is an easy task ... Those strings are long filepaths and I need to remove the disk name. Must be a generic method.

Got a workaround:
Fortunately colons are not allowed in Mac filenames, so a colon must be the end of the disk name. This gives the opportunity to change the colon to a space and get a list where the first element can be stripped.

bkshepard's icon

Does this work for you?

Max Patch
Copy patch and select New From Clipboard in Max.

Ernest's icon

Ah Well there is the third point about regular expressions. You can usually use something else or combine it with something else to simplify the task. My maC is not currently connected to a monitor, so I cant test it, but the Max objects which can help are relativepath and related objects.

vichug's icon
Max Patch
Copy patch and select New From Clipboard in Max.

even this maybe

Peter Ostry's icon

BKSHEPARD, VICHUG, both of your codes work just perfect, thanks.
I prefer BKSHEPARD's because of the beautiful ornamental symmetry of the pattern.
Must look great on an alien spaceship.

@VICHUG
Reason for RegEx: For file deletion I have to go via [shell] and for that the disk name must be stripped.

vichug's icon

heh... i just removed the left parenthesis from Bkshepard's solution, so as to avoid needing an ecils afterwards - but if you like the parenthesis :p

jko's icon

The regex that does exactly what you are asking for

(How to remove everything up to the first slash?

Max Patch
Copy patch and select New From Clipboard in Max.

would be regexp /.*

But check the conformpath object wich does exactly what you want. And if you use the absolutepath object afterwards you can even check if the file exists before sending your path-string to the next process

bkshepard's icon

Also be aware that--regardless of which regexp version you use--if the path has spaces in it, you will get the output with quotes around it. You can use the [fromsymbol] object to take care of that.

Max Patch
Copy patch and select New From Clipboard in Max.

Peter Ostry's icon

JKO, thanks for the simple pattern, looks logical and works.

BKSHEPARD, yes, I am used to the fromsymbol-tosymbol game. My next problem was to escape the spaces before going to [shell] because we cannot check the string in Max. Finally found a mysterious sprintf code in the web which I don't understand, but this combo works perfect for me:
[regexp /.*]
[sprintf mv \\\"%s\\\" ~/.Trash]
removes the disk name and deletes a file regardless of spaces in the path.