Click here to Skip to main content
15,890,690 members
Home / Discussions / C#
   

C#

 
GeneralRe: Regular Expression to convert from PHP to C# Pin
AngryC25-Jun-06 15:05
AngryC25-Jun-06 15:05 
GeneralRe: Regular Expression to convert from PHP to C# Pin
Graham Nimbley25-Jun-06 15:10
Graham Nimbley25-Jun-06 15:10 
GeneralRe: Regular Expression to convert from PHP to C# Pin
AngryC25-Jun-06 16:51
AngryC25-Jun-06 16:51 
GeneralRe: Regular Expression to convert from PHP to C# [modified] Pin
Graham Nimbley26-Jun-06 8:39
Graham Nimbley26-Jun-06 8:39 
GeneralRe: Regular Expression to convert from PHP to C# [modified] Pin
AngryC26-Jun-06 11:29
AngryC26-Jun-06 11:29 
GeneralRe: Regular Expression to convert from PHP to C# [modified] Pin
Graham Nimbley26-Jun-06 11:56
Graham Nimbley26-Jun-06 11:56 
GeneralRe: Regular Expression to convert from PHP to C# Pin
AngryC26-Jun-06 12:34
AngryC26-Jun-06 12:34 
GeneralRe: Regular Expression to convert from PHP to C# [modified] Pin
Graham Nimbley26-Jun-06 13:05
Graham Nimbley26-Jun-06 13:05 
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].";
		
		// Replace open color tag
		input=Regex.Replace(input,@"\[color=([^\]]*?)\]","<color=$1>");
		
		// Replace close color tag
		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
GeneralRe: Regular Expression to convert from PHP to C# [modified] Pin
AngryC26-Jun-06 13:16
AngryC26-Jun-06 13:16 
GeneralRe: Regular Expression to convert from PHP to C# Pin
Graham Nimbley26-Jun-06 13:21
Graham Nimbley26-Jun-06 13:21 
GeneralRe: Regular Expression to convert from PHP to C# Pin
AngryC26-Jun-06 13:30
AngryC26-Jun-06 13:30 
GeneralRe: Regular Expression to convert from PHP to C# Pin
Graham Nimbley26-Jun-06 13:41
Graham Nimbley26-Jun-06 13:41 
QuestionDeserialize XML by reverse-engineering class def Pin
Ed 5425-Jun-06 5:18
Ed 5425-Jun-06 5:18 
AnswerRe: Deserialize XML by reverse-engineering class def Pin
Guffa25-Jun-06 6:35
Guffa25-Jun-06 6:35 
GeneralRe: Deserialize XML by reverse-engineering class def Pin
Ed 5425-Jun-06 16:48
Ed 5425-Jun-06 16:48 
AnswerRe: Deserialize XML by reverse-engineering class def Pin
Guffa25-Jun-06 18:52
Guffa25-Jun-06 18:52 
GeneralRe: Deserialize XML by reverse-engineering class def Pin
Ed 5426-Jun-06 12:57
Ed 5426-Jun-06 12:57 
QuestionUnderstanding DataSets... [modified] Pin
martin_hughes25-Jun-06 4:56
martin_hughes25-Jun-06 4:56 
AnswerRe: Understanding DataSets... Pin
Robert Rohde25-Jun-06 20:10
Robert Rohde25-Jun-06 20:10 
QuestionOptional field selection SQL Pin
WillemM25-Jun-06 4:30
WillemM25-Jun-06 4:30 
AnswerRe: Optional field selection SQL Pin
Michael P Butler25-Jun-06 5:04
Michael P Butler25-Jun-06 5:04 
GeneralRe: Optional field selection SQL Pin
WillemM25-Jun-06 5:28
WillemM25-Jun-06 5:28 
Questionbug in HScrollBar control object Pin
3Dizard25-Jun-06 4:17
3Dizard25-Jun-06 4:17 
AnswerRe: bug in HScrollBar control object [modified] Pin
Graham Nimbley25-Jun-06 10:12
Graham Nimbley25-Jun-06 10:12 
GeneralRe: bug in HScrollBar control object Pin
3Dizard26-Jun-06 4:28
3Dizard26-Jun-06 4:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.