Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to generate a string from a Regular Expression?

Posted on 2009-06-28
12
Medium Priority
?
832 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 80 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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 80 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 80 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

DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 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