GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

substring-before

The substring-before function returns a string that is the part of a given string before a given substring.

The `substring-before` function returns a string that is the part of a given string before a given substring.

## Syntax

```plain
substring-before( haystack, needle )
```

### Parameters

- `haystack`
- : The string to be evaluated. Part of this string will be returned.
- `needle`
- : The substring to search for. Everything before the first occurrence of `needle` in `haystack` will be returned.

### Return value

A string.

## Examples

| XPath Example | Output |
| ------------------------------- | ---------------- |
| `substring-before('aa-bb','-')` | `aa` |
| `substring-before('aa-bb','a')` | `(empty string)` |
| `substring-before('aa-bb','b')` | `aa-` |
| `substring-before('aa-bb','q')` | (empty string) |

## Specifications

[XPath 1.0 4.2](https://www.w3.org/TR/xpath-10/#function-substring-before)

## Gecko support

Supported.

source: MDN Web Docs mirror · page

Cite this

"substring-before". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/XML/XPath/Reference/Functions/substring-before

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·