regular expression in formula to investigate

I found this very beautiful and useful formula to estract filename in a cell:

=REPLACE(REPLACE(CELL("filename"),FIND(".",CELL("filename"),1),(LEN(CELL("filename"))-FIND(".",CELL("filename"),1)+1),""),1,SEARCH("/[^/]*$", CELL("filename")),"")

I cannot understand this part:
SEARCH("/[^/]*$", CELL("filename")
I know it search in CELL("filename")
but I cannot understund the criteria "/[^/]*$"

from the tests it seems to find the last "/" in any string, and if you substitute the "/" with "." it works again finding the last ".", it is very useful .... :slight_smile: :slight_smile: :slight_smile: :slight_smile:

could somebody so marvellously noble and well-bred to explain the regular eapressions here used??

...a couple of beer paid for you...:slight_smile: :slight_smile: :slight_smile:

manythanks, ciao, pier

[...]
I cannot understand this part:
SEARCH("/[^/]*$", CELL("filename"))
I know it search in CELL("filename") but I cannot understand the criteria "/[^/]*$" from the tests it seems to find the last "/" in any string, and if you substitute the "/" with "." it works again finding the last ".", it is very useful .... :slight_smile: :slight_smile: :slight_smile: :slight_smile:

could somebody so marvellously noble and well-bred to explain the regular expressions here used??

I'm not even ordinarily noble - certainly not marvellously so - and I was only ordinarily bred; will I do?

The first character in the text string is the slash that you are looking for. A string in square brackets matches any single character which appears in that string. But if the first character is a circumflex (as here), it matches any single character *not* in that string. So leftbracket-circumflex-slash-rightbracket matches any single character other than a slash. The asterisk following this pattern causes a match with zero or more characters (as many as possible, in fact) preceding it - in this case the bracketed string. So the bracketed part followed by the asterisk together match as many characters as possibly not including a slash. The dollar sign locks the pattern to the end of a paragraph - in this case, the end of the entire text in the cell. So the whole string finds a slash followed by many not-slash characters, but only at the end of the string. As you say, that means everything from the last slash in the string to the end. The SEARCH() function then returns the position of the start of the matched text: the position of the last slash.

...a couple of beer paid for you...:slight_smile: :slight_smile: :slight_smile:

How kind! I'll enquire of my mail service provider how soon they can permit liquid attachments.

I trust this helps.

Brian Barker

[...]
I cannot understand this part:
SEARCH("/[^/]*$", CELL("filename"))
I know it search in CELL("filename") but I cannot understand the
criteria "/[^/]*$" from the tests it seems to find the last "/" in any
string, and if you substitute the "/" with "." it works again finding
the last ".", it is very useful .... :slight_smile: :slight_smile: :slight_smile: :slight_smile:

could somebody so marvellously noble and well-bred to explain the
regular expressions here used??

I'm not even ordinarily noble - certainly not marvellously so - and I
was only ordinarily bred; will I do?

...enough noble to be opensource knight...:slight_smile: :slight_smile:

The first character in the text string is the slash that you are looking
for. A string in square brackets matches any single character which
appears in that string. But if the first character is a circumflex (as
here), it matches any single character *not* in that string. So
leftbracket-circumflex-slash-rightbracket matches any single character
other than a slash. The asterisk following this pattern causes a match
with zero or more characters (as many as possible, in fact) preceding it
- in this case the bracketed string. So the bracketed part followed by
the asterisk together match as many characters as possibly not including
a slash. The dollar sign locks the pattern to the end of a paragraph -
in this case, the end of the entire text in the cell. So the whole
string finds a slash followed by many not-slash characters, but only at
the end of the string. As you say, that means everything from the last
slash in the string to the end. The SEARCH() function then returns the
position of the start of the matched text: the position of the last slash.

thank you very much, I understood now, and I will better study regular expressions...:slight_smile:
as you know is there some way to start search from the right of strings??

...a couple of beer paid for you...:slight_smile: :slight_smile: :slight_smile:

How kind! I'll enquire of my mail service provider how soon they can
permit liquid attachments.

…in technology we trust… for now only USB beer… :slight_smile: :slight_smile: :slight_smile: :slight_smile:
http://beer.about.com/od/beertastinganddrinking/ig/Beer-Gadgets--Gizmos---Goodies/-Beer--Filled-USB-Flash-Drive.htm
but I don't know the flavour…
…and if you pass from Latina-Italy email to me, a real beer can be found more easily…:slight_smile: :slight_smile:

I trust this helps.

Brian Barker

ciao, Pier

P.S. sorry if my bad english can generate misunderstunding, I'm only joking :slight_smile:

as you know is there some way to start search from the right of strings??

Not directly that I know of. I think you just need to use the $ character - as here - to lock the pattern you are matching to the end of the text (or of a paragraph, in the case of a text document).

...in technology we trust..... for now only USB beer... :slight_smile: :slight_smile: :slight_smile: :slight_smile:

Ho, ho! Splendid! Thanks.

P.S. sorry if my bad english can generate misunderstanding, I'm only joking :slight_smile:

It's perfectly understandable.

Brian Barker

...:slight_smile: :slight_smile: :slight_smile: many thanks...:slight_smile: :slight_smile: