Solved

How to generate a string from a Regular Expression?

Posted on 2009-06-28
12
825 Views
Last Modified: 2012-05-07
I have a regular expression using which i need to generate its corresponding string token..
0
Comment
Question by:unicorn_rm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
12 Comments
 
LVL 6

Expert Comment

by:Ravi Kalla
ID: 24734483
A regular expression can generate infinate strings. So, a single string token can't be generated to it. Do you want to find the strings that satisfies the Regular Expression from a list of strings?
Mention you requirement in detail.
 
0
 
LVL 39

Expert Comment

by:abel
ID: 24744034
Perhaps you mean to show the string representation of a regular expression in memory? The following code snippet shows how to print the internal regular expression as it was passed into the regex  constructor. It prints the following:

[hH]ello\s+[wW]orld$

// output the internal regular expression
Regex re = new Regex(@"[hH]ello\s+[wW]orld$");
Debug.WriteLine(re.ToString());

Open in new window

0
 

Accepted Solution

by:
tazmaster earned 20 total points
ID: 24887998
Primarily regular expressions are used on Strings to extract bits of it that match the regular expression that you've specified. if you're interested in identifying all of the various Strings that can match a regular expression rather than identifying them in an already existing one then it can be tricky, if you have a well defined expression then you may be able to limit the output, otherwise you might as well use the brute force method and create all of the conceivable combinations of characters and apply the regular expression to them to see if it matches or not.
0
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
LVL 84

Expert Comment

by:ozo
ID: 24888010
what kind of correspondence are you talking about?
0
 
LVL 39

Assisted Solution

by:abel
abel earned 20 total points
ID: 24895361
> create all of the conceivable combinations of characters and apply the > regular expression to them to see if it matches or not.
that would be funny, say we do not consider unicode, but only us-ascii, which has 128 codepoints (127, plus codepoint 0), and we try the following regex: ".*a.*" (yes, I know it can be written as "a" too, I just want to make a point with the .*) . Then we apply all possible combinations.... let's see (each X is any character, a is a):

a = 1
aX = 128 + 1 = 129
Xa = 128 + 129 = 257
aXX = 128 * 128 + 257 = 16641
XaX = 128 * 128 + 16641 = 33025
XXa = ....
 aXXX
XaXX
XXaX
XXXa = 8438017

I know, not that much, but add on more character and an average computer will not have enough memory: 1,350,615,297. yet another character and your disk cannot copy with it anymore... Not really a tempting idea to use brute force, I think..., but interesting nonetheless.

As ozo pointed out in the first answer, there are often an infinite amount of strings that can match a certain expression (the above is one such). Which one would you return?

-- Abel --


0
 

Expert Comment

by:tazmaster
ID: 24900408
i wasn't making a serious suggestion... i was attempting to demonstrate the futility of attempting it.
0
 
LVL 39

Expert Comment

by:abel
ID: 24902575
;-)
then I think we made the right point together :D
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 20 total points
ID: 24902652
0
 
LVL 39

Expert Comment

by:abel
ID: 24902771
Nice one, I particularly like the Explain module (I don't really see the point in Genex... but hey, if that's the request ;-)

I think these answers are very valuable and all that for 50p ;-) ....but the q. has been abandoned since the start...
0
 
LVL 39

Expert Comment

by:abel
ID: 25284251
This question received ample coverage, multiple experts come to the same conclusion: "cannot be done" unless you have infinite time/space.

http:#24744034 (abel) shows how to tell the string repres. of a regex
http:#24887998 (tazmaster) explains the futility of getting matching strings
http:#24895361 (abel) elaborates on that
http:#24902652 (ozo) giving another angle with Explain and GenEx

Suggestion: equal split between http:#24887998 (tazmaster), http:#24895361 (abel) and http:#24902652 (ozo).
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question