473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Listing all regexs possibilities

I have some regex lists, and I need to print all possibilities from them.

Like that:

print abac[ao]

that would print:

abaca
abaco

Can this be possible?
Apr 2 '08 #1
11 1912
eWish
971 Expert 512MB
I would say yes. What have you tried?

--Kevin
Apr 2 '08 #2
Yeah, but it didn't work:

$ perl -e 'print "abac[ao]\n"'
abac[ao]
Apr 2 '08 #3
eWish
971 Expert 512MB
If you want to do 'a' or 'o' then you would need abc[a|o].

Expand|Select|Wrap|Line Numbers
  1. my @array = qw(abca abcd abco abca abco abci abcf abca);
  2.  
  3. foreach (grep/abc[a|o]/, @array) {
  4.     print $_, "\n";
  5. }
--Kevin
Apr 2 '08 #4
But I don't want to supply words...I'm looking for something like this:

print "abc[a|o]";

or

print "test?[a-z]"

and go on...

there is a way to do that?
Apr 3 '08 #5
eWish
971 Expert 512MB
I used a list as an example. Can you show me 10 lines of expected output, because I am having trouble understanding what you are wanting to do I guess. Also, where is your data from from?

Edit: Are you looking for something like this:
Expand|Select|Wrap|Line Numbers
  1. print join("\n", ('testa ..testz'));
Output:
Expand|Select|Wrap|Line Numbers
  1. testa
  2. testb
  3. testc
  4. testd
  5. and so on to testz
--Kevin
Apr 3 '08 #6
Ganon11
3,652 Expert 2GB
The OP has a list of regular expressions, and wants to be able to print all possible patterns the regex will match. So if he had a simple one like /\d/, it would print each string that the regex would match - namely, 0, 1, 2, etc. etc.
Apr 3 '08 #7
Ganon11: that's exacly what I'm trying to do.
Apr 3 '08 #8
eWish
971 Expert 512MB
I have never done it, but I am sure that it is possible.

--Kevin
Apr 4 '08 #9
Ganon11
3,652 Expert 2GB
You can probably do it with a recursive function. Imagine this:

You are building a word step by step when you encounter a special character - be it a \d, or a [a-z], or whatever. You then loop over the possible matches, calling the function with a partial string (your word so far, plus the character your loop is on) and the pattern.

When there are no more special cases, you print out the word and return, and let recursion work its magic.

Note: as soon as you have a modifier like + or *, you will have an infinite number of possibilities (e.g. /\d+/ will match 1, 11, 111, 1111, ..., 11111111111111111...., etc. etc. So you need to make sure that doesn't happen.
Apr 4 '08 #10
KevinADC
4,059 Expert 2GB
I have some regex lists, and I need to print all possibilities from them.

Like that:

print abac[ao]

that would print:

abaca
abaco

Can this be possible?
Possible? Yes. Easy and automatic? No. Perl will not expand your regexp character class automatically and print all possible permutations, you will pretty much have to hard code that yourself.
Apr 4 '08 #11
It's ok guys, I was hoping for a easy solution. It's better forget it. Thanks!
Apr 9 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dirk Hagemann | last post by:
Hi! I'm using this code to list all computers of our WinNT-Domains: import win32com.client from pprint import pprint as p domain='domainX' auswahl='computer' def enumerate(domain,auswahl):...
9
by: Gary | last post by:
Hello, Is it possible to dynamically update a textbox with words chosen from a list using form checkboxes and javascript? Gary
66
by: Alan Illeman | last post by:
Is there a listing of serif fonts and san-serif fonts somewhere? Regards, Alan -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A:...
19
by: SU News Server | last post by:
I've struggled with this for quite a while and I'm am just not sure what is going on. I have the following code import os def buildList( directory='/Users/mkonrad' ) dirs = listing =...
3
by: David Jacques | last post by:
I am trying to get a list of all files of a certain extension type on disk to do some processing in a loop. The code needs to be portable to UNIX, so I need to use plain c functionality. Does...
22
by: MLH | last post by:
If 3 things can be in one of 2 states, the number of possible combinations is equal to 2^3. But if I have 3 things, 2 of which can be in 2 states and the other in 3 states, what's the simplest...
1
by: Johnny Jörgensen | last post by:
I've got a serious problem. I've got Visual Studio 2005 installed, and of course I'm using the Pretty Listing formatting function. When I start up VS, everything is fine, but after a while (which...
8
by: Petar | last post by:
I was just wondering. What if you have a 'Employees' class and you want to list all the employees. Currenlty i'm seeing to possibilities: - create a 'listAll' function inside the class which...
5
by: jain236 | last post by:
HI every body, i am always getting the following error while parsing a directory . i am reading a directory by doing ls and trying to find out the name,type,size, mtime and mode of files from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.