Hi, I have a list of strings. And I want to find the subset which
matches a particular regular expression.
import re
ll = ('a', 'b', 's1', 's2', '3s')
p = re.compile('^s.*')
newList = filter(lambda s: p.match(s), ll)
I suppose there should be simple function to do this in re module. Is
there any?
I searched google, but could not find one, may be for keywords were not
perfect.
Thanks.
Suresh 5 939
"jm*******@no.spam.gmail.com" <jm*******@gmail.comwrites:
Hi, I have a list of strings. And I want to find the subset which
matches a particular regular expression.
import re
ll = ('a', 'b', 's1', 's2', '3s')
p = re.compile('^s.*')
newList = filter(lambda s: p.match(s), ll)
I suppose there should be simple function to do this in re module. Is
there any?
I searched google, but could not find one, may be for keywords were not
perfect.
I dont believe there exists such a function. I would have written
it using a list comprehension.
>>import re ll = ('a', 'b', 's1', 's2', '3s') p = re.compile('^s.*') newList = [s for s in ll if p.match(s)] newList
['s1', 's2']
--
Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info jm*******@no.spam.gmail.com wrote:
Hi, I have a list of strings. And I want to find the subset which
matches a particular regular expression.
import re
ll = ('a', 'b', 's1', 's2', '3s')
p = re.compile('^s.*')
newList = filter(lambda s: p.match(s), ll)
I suppose there should be simple function to do this in re module. Is
there any?
I searched google, but could not find one, may be for keywords were not
perfect.
Thanks.
Suresh
I think I'm having some network problems. I'll try again. Also the
previous "attempt" had a typo (perhaps a freudian slip).
",".join(some_list).
By the way, don't name your own objects with the names of built-in
types, such as "list" or "str", etc. jm*******@no.spam.gmail.com wrote:
Hi, I have a list of strings. And I want to find the subset which
matches a particular regular expression.
import re
ll = ('a', 'b', 's1', 's2', '3s')
p = re.compile('^s.*')
newList = filter(lambda s: p.match(s), ll)
I suppose there should be simple function to do this in re module. Is
there any?
#>>s = ('a', 'b', 's1', 's2', 'c')
#>>import re
#>>regexp = re.compile('^s.*')
#>>filter( regexp.match, s)
#('s1', 's2')
#>>>
Gerard jm*******@no.spam.gmail.com wrote:
Hi, I have a list of strings. And I want to find the subset which
matches a particular regular expression.
import re
ll = ('a', 'b', 's1', 's2', '3s')
p = re.compile('^s.*')
newList = filter(lambda s: p.match(s), ll)
or
newList = [s for s in ll if p.match(s)]
I suppose there should be simple function to do this in re module. Is
there any?
No.
Peter
James Stroud wrote:
[snip]
I think I'm having some network problems. I'll try again. Also the
previous "attempt" had a typo (perhaps a freudian slip).
Also this time you replied to the wrong thread :-)
>
",".join(some_list).
By the way, don't name your own objects with the names of built-in
types, such as "list" or "str", etc.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jacob Weber |
last post by:
If I do a search with a regular expression that uses parenthesized
subexpressions, is there a way to find out where it found the
subexpressions?
For example, say I do:
"bb".search(/b(.)/g);
...
|
by: B Moor |
last post by:
I have a database with 100,000's records, each with a unique
reference, eg
A123BNK456
I would like to generate a search facility whereby we can choose an
exact match or partial match, where the...
|
by: RAJASEKHAR KONDABALA |
last post by:
Hi,
Does anybody know what the fastest way is to "search for a value in a
singly-linked list from its tail" as oposed to its head?
I am talking about a non-circular singly-linked list, i.e.,...
|
by: olaufr |
last post by:
Hi,
I'd need to perform simple pattern matching within a string using a
list of possible patterns. For example, I want to know if the substring
starting at position n matches any of the string I...
|
by: Bob |
last post by:
I need to create a Regex to extract all strings (including quotations) from
a C# or C++ source file. After being unsuccessful myself, I found this
sample on the internet:
...
| |
by: nufuhsus |
last post by:
Hello all,
First let me appologise if this has been answered but I could not find
an acurate answer to this interesting problem.
If the following is true:
C:\Python25\rg.py>python
Python...
|
by: dayanand ramasubbu |
last post by:
Hi,
I want to get the best possible match for a strings among a list of strings.
For eg, my string to be matched is hi/howareyou?rudoingok which needs to be matched against the below list,
...
|
by: Astley Le Jasper |
last post by:
Sorry for the numpty question ...
How do you find the reference name of an object?
So if i have this
bob = modulename.objectname()
how do i find that the name is 'bob'
|
by: Ben |
last post by:
Hello All:
I am new to Python, and I love it!! I am running 2.6 on Windows. I
have a flat text file here is an example of 3 lines with numbers
changed for security:
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |