1

i have a string similar to this one:

Hi, <<\name>> <<\surname>>, this is an example <<\test>>.

I what a regex that match and split this string in:

"Hi, " 
<<\name>>
" "
<<\surname>> 
", this is an example " 
<<\test>>
"."

I tried this one: (<<\*.*?>>)|(>>*.*?<<), but doesn't work. It's possible? Thanks.

2
  • is <<*.?>> a typo? it would be wrong. it's <<.*?>> Commented Apr 8, 2011 at 13:42
  • and what do you want to do with the (>>.*?<<) anyway? it doesn't help to your solution, does it? and probably even confuses the regex Commented Apr 8, 2011 at 13:57

2 Answers 2

2

You could use this expression (it uses positive lookaheads and positive lookbehinds):

<<.*?>>|(?<=>>|^).*?(?=<<|$)

it matches strings surrounded by << and >> symbols, strings which are between these symbols and strings from the begin to << and to the end from >>.

You could find a C# example on ideone.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much Alex...that's was! The only thing is, this regex doesn't much carriage return, but nevermind.
0

use str_replace

$str =' Hi, <<\name>> <<\surname>>, this is an example <<\test>>.';
$old= array('<<','>>');
$new =array('"<<','>>"');
$str2=str_replace ($old,$new,$str);
//retruns Hi, "<<\name>>" "<<\surname>>", this is an example "<<\test>>".

2 Comments

maybe he's not developing in php?
sorry but i want split no replace. Im' developing in VB.NET

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.