3 Replies - 766 Views - Last Post: 17 March 2010 - 10:45 PM Rate Topic: -----

#1 nyxynyx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-March 10

Simple Regex Question

Posted 17 March 2010 - 09:30 PM

Let's say I have the following input:

{{Hello|Hi|Hey} {world|earth} | {Goodbye|farewell} {noobs|n3wbz|n00blets}}


And I want that to turn into any of the following:

Hello world 
Goodbye noobs 
Hi earth
farewell n3wbz 


Paying attention to the way the "spinning" syntax is nested. It could be nested a billion layers deep for all we know.

I can do this easy, except once they're nested like the above example my regex messes up and the results are not correct.

The word that will be chosen will be randomized.

Any help greatly appreciated! Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Simple Regex Question

#2 EtherealMonkey   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 33
  • Joined: 17-March 10

Re: Simple Regex Question

Posted 17 March 2010 - 09:48 PM

When you say "Let's say I have the following input", does this mean that it be fed interactively to the program? Or is it to be hard coded?

Because, I would try to place the string values in a collection (my limited experience would place array high on the list - YMMV)

Then I would parse the first string off and find it in the correct collection (and note the index if that is what is driving the choice of the alternate strings).

Sorry, I'm kind of new myself - but I really don't think that the question is clear. I only really began to understand it as I was finishing this up (I think?)

This post has been edited by EtherealMonkey: 17 March 2010 - 09:49 PM

Was This Post Helpful? 0
  • +
  • -

#3 nyxynyx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-March 10

Re: Simple Regex Question

Posted 17 March 2010 - 09:56 PM

It will be fed into the program. (I don't think it'll matter if its hard-coded as well). Which part of the question is unclear? I'll try to explain that part again hehe.

This post has been edited by nyxynyx: 17 March 2010 - 09:57 PM

Was This Post Helpful? 0
  • +
  • -

#4 EtherealMonkey   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 33
  • Joined: 17-March 10

Re: Simple Regex Question

Posted 17 March 2010 - 10:45 PM

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace yours
{
	class YourClass()
	{
		// Example string array for greetings
		private string[] _greetz = {"Hello","Hi","Hey"};
		// String array re-arranged to RegEx pattern to match words in _greetz
		private const string _gr33tz = "(" + _greetz[0] + "|" + _greetz[1] + "|" +_greetz[2] + ")";
		
		// Parse the input string
		// Determine the position of the found string in _greetz (to avoid re-use - I presume)
		// Use prescribed logic, or randomize the selection of the replacement string from _greetz
		
		//Repeat as needed ;-)
	}
}



More like pseudocode ;-)

HTH

This post has been edited by EtherealMonkey: 17 March 2010 - 10:49 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1