$basename (parse-spec) function
The portion of the word given by parse-spec is returned, where the returned portion is delimited by the last punctuation mark of the word (if any). If the parse-spec value does not return a word, the match specification is not matched. This function is especially useful in a nested specification. For a similar function that is useful for finding the base name of file paths, see fname-parse-spec-function.
The following examples show target strings, parse expressions, and return values:
Target string | Parse expression | Return value |
|---|---|---|
File README | $basename ($2) | README |
File Readme.txt | $basename (file *) | Readme |
Test Addr: 192.168.1.31.0 | $basename (addr: *) | 192.168.1.31 |
Test Addr: 10.1.1.38/25 | $basename (addr: *) | 10.1.1.38 |
Test Addr: /10.1.2.3/00/35 | $basename (addr: *) | /10.1.2.3/00 |
Test string ABC. | $basename ($3) | ABC |
Test string AAA | $basename ($4) | No match Explanation: There is no fourth word in the string. |
Test string value | $basename (xxx: *) | No match Explanation: There is no match for xxx: * in the target string. |
Related topic