|
See if we can come up with right phrases for a good application based on your hints:
1 - User Friendly
2 - Creative
3 - Intuitive
4 - Versatile
Best,
Jun
|
|
|
|
|
Nice!!;)
I like the "Shortest distance between two points is a straight line" thinking of yours Jun.
|
|
|
|
|
|
|
Colin Angus Mackay wrote: Talking to yourself?
second time last week someone whined "can't find it on google" 20 seconds later... there it is on my google results. You really gotta wonder when they can't even use a search engine maybe they should consider a different field.
|
|
|
|
|
Hello guys,
I have the following Regular Expression, I want to convert it from PHP to C#.
$aVar = preg_replace("/[\r\n]{1,2}(.+)\#(.*)[\r\n]{1,2}/U", "$myRightVar\\1$myCenterVar\\2$myLeftVar\r", $aVar);
( http://www.php.net/preg_replace )
I tried a lot but I failed. Can you please help me. Thanks.
|
|
|
|
|
The Regex is okay, at least it compiles and Expresso doesn't complain. What shall it match actually?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I'm new to C#. This is the first time I'm using Regular expression. Can you give me the complete C# tag please?
What the code does is taking any line that contains # charachter and add $myRightVar at the beginning of the line then replace # with $myCenterVar and add $myLeftVar at the end of the line.
|
|
|
|
|
|
string regex=@"[\r\n]{1,2}(.+)\#(.*)[\r\n]{1,2}";
string replace=String.Format("{0}\\1{1}\\2{2}\r",myRightVar,myCenterVar,myLeftVar);
string output=Regex.Replace(input,regex,replace);
Haven't got VS in front of me, but this (hopefully) should work.
Graham.
-- modified at 15:34 Sunday 25th June, 2006
|
|
|
|
|
It's almost working... the problem is I'm NOT getting the old left text and the old right text shown. I'm getting \1 and \2.
What's wrong?
Many thanks.
|
|
|
|
|
This is a different approach, maybe it works for you?
string regex = @"[\r\n]{1,2}(.+)\#(.*)[\r\n]{1,2}";
Match m = Regex.Match(input, regex);
if (m.Success)
{
string output = String.Format("{0}{1}{2}{3}{4}\r", myRightVar, m.Groups[1], myCenterVar, m.Groups[2], myLeftVar);
Console.WriteLine(output);
}
Probably this might also work, it's way shorter:
string output2 = Regex.Replace(input, regex, String.Format("{0}$1{1}$2{2}\r", myLeftVar, myCenterVar, myRightVar));
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks a lot but it didn't work for me
The string I am parsing contains the following:
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.
toto toto toto # toto toto toto
toto toto toto # toto toto toto
toto toto toto # toto toto toto
toto toto toto # toto toto toto
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.
So I want to add alter the content on the following way:
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.
[myLeftVar]toto toto toto [myCenterVar] toto toto toto[myRightVar]
[myLeftVar]toto toto toto [myCenterVar] toto toto toto[myRightVar]
[myLeftVar]toto toto toto [myCenterVar] toto toto toto[myRightVar]
[myLeftVar]toto toto toto [myCenterVar] toto toto toto[myRightVar]
And so on...
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.
Please help.
|
|
|
|
|
This should be it.
string regex=@"(.+)\#(.+)\r\n";
string replace=String.Format("{0}$1{1}$2{2}\r\n","Left","Center","Right");
string output=Regex.Replace(input,regex,replace);
I've tweaked the regex as I was having problem with it.
I've dumped the code I used to test it:
using System;
using System.Text.RegularExpressions;
public class Testy
{
public static void Main()
{
string input="bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.\r\n\r\n"+
"toto toto toto # toto toto toto\r\n"+
"toto toto toto # toto toto toto\r\n"+
"toto toto toto # toto toto toto\r\n"+
"toto toto toto # toto toto toto\r\n\r\n"+
"bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla";
string regex=@"(.+)\#(.+)\r\n";
string replace=String.Format("{0}$1{1}$2{2}\r\n","Left","Center","Right");
string output=Regex.Replace(input,regex,replace);
Console.WriteLine(output);
}
}
|
|
|
|
|
Thanks a lot Graham it worked
|
|
|
|
|
Good to know.
Regexs are good fun, but can be a pain in the a**e sometimes!!
|
|
|
|
|
I have this left
$content = preg_replace('#[color=([^-]+)-(.*)[/color]#Uis', '$2', $content);
This is simply to parse bbcode color tag, e.g. [color=red]text[/color]
Please help.
|
|
|
|
|
Hi
using System;
using System.Text.RegularExpressions;
public class Testy
{
public static void Main()
{
string input="This is a [color=red]red[/color] color and this is a [color=blue]blue[/color] color.";
string regex=@"\[color=[^\]]*?\](.*?)\[/color\]";
string output=Regex.Replace(input,regex,"$1");
Console.WriteLine(output);
}
}
There was a couple of things wrong with the regex. The original was greedy, and is now lazy. Also some escaping of ']' and '[' was needed.
Graham
-- modified at 14:41 Monday 26th June, 2006
|
|
|
|
|
Thanks a lot but what if I want to change the brakets type, say:
-color=red- text text -color!-
How can I parse it to:
<font color="red"> text text </font>
|
|
|
|
|
string regex=@"\[color=([^\]]*?)\](.*?)\[/color\]";
string replace=@"<color=$1>$2</color>";
string output=Regex.Replace(input,regex,replace);
If you are intending to place bbcode for a certain number of tags, it might be easier to use a generic regex.
-- modified at 17:58 Monday 26th June, 2006
|
|
|
|
|
Many thanks, It worked, but not when it's nested:
text text text text [color=red]hello [color=green]ok[/color] test ok[/color]
Is there an easy solution for this?
|
|
|
|
|
The easy way would be to treat the opening and closing tags independently of each other.
using System;
using System.Text.RegularExpressions;
public class Testy
{
public static void Main()
{
string input="This is a [color=red]red sentence with [color=blue]some blue[/color] words[/color].";
input=Regex.Replace(input,@"\[color=([^\]]*?)\]","<color=$1>");
input=Regex.Replace(input,@"\[/color\]","</color>");
Console.WriteLine(input);
}
}
The hard way would involve some complex regexs. Will try to come up with something.
Graham.
[Edit]
Hmmm. It appears that this might be pretty difficult. The problem is that regexs by definition match up by looking forward. To look for nested tags, requires searching the text in tree-wise fashion. To do this in linear text requires requires bilaterial searching, looking forward from the left at the same time looking backwards from the right.
Problem is that regexes are virtually impossible to do proper backwards searching. It may be possible to achieve the same effect with some creative code along side regexs.
-- modified at 19:13 Monday 26th June, 2006
|
|
|
|
|
Worked, again
Which one is better for the closing tab in your opinion:
This:
output = input.Replace("[/color]", "</color>");
Or this:
input=Regex.Replace(input,@"\[/color\]","</color>");
The first one is faster right?
I PHP normal function is faster than regular expression, is it the samething in C#?
-- modified at 19:16 Monday 26th June, 2006
|
|
|
|
|
They both do the same job. The first it a straight substitution, the second a regex. The first would be marginally faster to perform.
Have you read my edit on the harder solution?
|
|
|
|
|
I just did. Anyway, the easy method is more than enough for me.
I really appreciate your help.
|
|
|
|