views:

123

answers:

3

I have a string containing something 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

+1  A: 

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
}
Tim Pietzcker
I need to split it in 3 parts
streetparade
What three parts? jitter already modified my solution to also match the static strings (but it doesn't make much sense to capture static parts of a regex)...
Tim Pietzcker
+2  A: 
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
}
jitter
Thanks i need to split the text in 3 parts
streetparade
+1  A: 
myString.split("\n");

You'll get an array of 3 parts.

Alsciende