I have a string containing somethi开发者_运维技巧ng like this
"Hello bla bla bla bla ok, once more bla können. // this is static: it doesn't change
This is a text, this also a text. // this is dynamically added text it can change each time
My name mysurename // this is also static text
www.blabla.com
"
Now I have content and I have to get the first part of the string and the third part, I want to be able to have 3 parts, I think I have to split it using something like split();
string1 = "Hello bla bla bla bla ok, once more bla können.;
string2 = ""; // i have this part
string3 ="My name mysurename";
If it helps the first part ends with "können. "
and the third part ends with the url above // its a fictional URL
match = subject.match(/(First static string)([\s\S]*?)(Second static string)/);
if (match != null) {
statictext1 = match[1]; // capturing group 1
dynamictext = match[2]; // capturing group 2
statictext2 = match[3]; // capturing group 3
} else {
// Match attempt failed
}
myString.split("\n");
You'll get an array of 3 parts.
I'm not sure I can parse the question correctly, but it looks like you might be wanting to collect any text between two static strings. If that's right, then the answer is:
First static string(.*?)Second static string
In JavaScript:
match = subject.match(/First static string([\s\S]*?)Second static string/);
if (match != null) {
text = match[1] // capturing group 1
} else {
// Match attempt failed
}
精彩评论