Question: I have an expression.

```
var expression = "Q101='You will have an answer here like a string for instance.'"

```

I have a regular expression that searches the expression.

```
var regEx = new regExp(/=|<>|like/)

```

I want to split the expression using the regular expression.

```
var result = expression.split(regExp)

```

This will return the following:

```
["Q101", "'You will have an answer here ", " a string for instance'"]

```

This is not what I want.

I should have:

```
["Q101", "'You will have an answer here like a string for instance'"]

```

How do I use the regular expression above to split only on the **first** match?

Answer: 
JavaScript's `split` method won't quite do what you want, because it will either split on all matches, or stop after N matches. You need an extra step to find the first match, then split once by the first match using a custom function:

```js
function splitMatch(string, match) {
  var splitString = match[0];
  var result = [
    expression.slice(0, match.index),
    expression.slice(match.index + splitString.length)
  ];
  return result;
}

var expression = "Q101='You will have an answer here like a string for instance.'"

var regEx = new RegExp(/=|<>|like/)
var match = regEx.exec(expression)

if (match) {
  var result = splitMatch(expression, match);
  console.log(result);
}

```
While JavaScript's `split` method [does](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) have an optional `limit` parameter, it simply discards the parts of the result that make it too long (unlike, e.g. Python's `split`). To do this in JS, you'll need to split it manually, considering the length of the match —

```js
const exp = "Q101='You will have an answer here like a string for instance.'"

const splitRxp = /=|<>|like/
const splitPos = exp.search(splitRxp)
const splitStr = exp.match(splitRxp)[0]

const result = splitPos != -1 ? (
  [
    exp.substring(0, splitPos),
    exp.substring(splitPos + splitStr.length),
  ]
) : (
  null
);

console.log(result)
```