'Get two string from a multilines data in javascript
I tried to get 2 string from multilines data. I used Reguler Expression to match the string that I want. First string is just one line, but the second is multipleline. This is my RegEx function
const RegExp = /\/Data first:(.*) second:(.*\n.*)/
const first = RegExp.exec(text)[1]
const second = RegExp.exec(text)[2]
I have the following string
/Data first:this first must include second:this second and
third
fourth
.
.
.
and so on must include
But it's not working as I expected. What I got is like this
first: this first line
second: this second
third
But I need to get result is like this
first: this first line
second: this second
third
fourth
.
.
.
and so on
I tried a lot of things, but I can't figure it out.
Solution 1:[1]
You can try this \/Data first:(.*) second:(.*[\s\S]*). I tested with your data and it's working as your requirement. You can try this playground.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nick Vu |
