This is probably an easy question, but I can't find a function (maybe my
syntax is off...) to search for [a-z] in a string. If someone would
help out, I'd appreciate it!
Also, how would you recommend searching for the following in the same
string:
[a-z]
[A-Z]
[0-9]
-
My approach would be to perform four separte checks, but I'm thinking
there might be some cool approach that would use a dictionary or array.
Ideas?
Thanks,
Hank 10 25839
Also, how would I check if [a-z] is not in a string?
Thanks again,
Hank
Hank Kingwood wrote: This is probably an easy question, but I can't find a function (maybe my syntax is off...) to search for [a-z] in a string. If someone would help out, I'd appreciate it!
Also, how would you recommend searching for the following in the same string: [a-z] [A-Z] [0-9] -
My approach would be to perform four separte checks, but I'm thinking there might be some cool approach that would use a dictionary or array. Ideas?
Thanks, Hank
Hank Kingwood wrote: This is probably an easy question, but I can't find a function (maybe my syntax is off...) to search for [a-z] in a string. If someone would help out, I'd appreciate it!
Also, how would you recommend searching for the following in the same string: [a-z] [A-Z] [0-9] -
My approach would be to perform four separte checks, but I'm thinking there might be some cool approach that would use a dictionary or array. Ideas?
Are you looking for the actual string [a-z] in a string, or are you
looking for the regular expression [a-z] (any one lowercase letter)
Actual string: import re regex = re.compile('\[a-z\]') regex.search('123123[a-z]adsfasfd').group()
'[a-z]'
Regex pattern: import re regex = re.compile('[a-z]') regex.search('123123123a123123b123123c').group()
'a' regex.findall('123123123a123123b123123c')
['a', 'b', 'c']
You could also do: import re regex = re.compile('[a-z]|[A-Z]') regex.findall('123a23423b13123c123123A123B123C')
['a', 'b', 'c', 'A', 'B', 'C']
There are probably other ways to do it with list comprehensions, but
does that help?
Jay
Hank Kingwood wrote: Also, how would I check if [a-z] is not in a string?
following my re examples: import re regex = re.compile('[^a-z]') if regex.search('123123123132'): print "no lower letters!"
....
no lower letters!
There is a good regular expression tutorial on http://www.amk.ca/python/howto/regex/
jay
Jay Dorsey wrote: >>> regex = re.compile('[a-z]|[A-Z]') >>> regex.findall('123a23423b13123c123123A123B123C')
['a', 'b', 'c', 'A', 'B', 'C']
Line 1 above should have been [a-zA-Z] (although as posted it works as
well). Its just prettier the second way :-)
Jay
At 08:48 AM 10/2/2003, Hank Kingwood wrote: This is probably an easy question, but I can't find a function (maybe my syntax is off...) to search for [a-z] in a string. If someone would help out, I'd appreciate it!
Also, how would you recommend searching for the following in the same string: [a-z] [A-Z] [0-9] -
My approach would be to perform four separte checks, but I'm thinking there might be some cool approach that would use a dictionary or array. Ideas?
Sounds like a perfect application for regular expressions. Check out the re
module. Example: import re re.findall(r'[a-zA-Z0-9]*', 'This is fun')
['This', '', 'is', '', 'fun', '']
Bob Gailer bg*****@alum.rpi.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
On Thu, 02 Oct 2003 14:56:10 GMT, Hank Kingwood
<ha**@bogusaddress.xyz> wrote: Also, how would I check if [a-z] is not in a string?
import string
sometext = "whatever"
if not string.lowercase in sometext:
<do what you wanted to do> Thanks again, Hank
Hank Kingwood wrote: This is probably an easy question, but I can't find a function (maybe my syntax is off...) to search for [a-z] in a string. If someone would help out, I'd appreciate it!
Also, how would you recommend searching for the following in the same string: [a-z]
if string.lowercase in sometext:
[A-Z]
if string.uppercase in sometext: ...
[0-9]
if string.digits in sometext: ...
-
My approach would be to perform four separte checks, but I'm thinking there might be some cool approach that would use a dictionary or array. Ideas?
Thanks, Hank
As others have shown, you can of course do this with regular
expressions, but the string module is your friend in this case, and
makes for very readable code, which is also unicode-ready, since
string.(lower|upper)case also contain accented and other characters.
Just do a dir(string) to see what other goodies there are...
--
Christopher
On Thu, 02 Oct 2003 16:13:59 GMT, myself <kl******@chello.at> wrote: which is also unicode-ready, since string.(lower|upper)case also contain accented and other characters.
Ouch, I take it back (the unicode thing), it's just all the
lower/uppercase letters from the latin-1 set, but not in unicode...
Also, if you want to check for ONLY [a-z], you can check for
string.lowercase[0:26]...
hasty, hasty, hasty...
--
Christopher
Christopher Koppler wrote: Also, how would I check if [a-z] is not in a string? import string
sometext = "whatever" if not string.lowercase in sometext: <do what you wanted to do>
Let's see: import string sometext = "whatever" if not string.lowercase in sometext:
.... print "do what you wanted to"
....
do what you wanted to
I doubt that this is what you expected.
s1 in s2
tests if s1 is a substring of s2, but you want
def contains(s, chars):
for c in s:
if c in chars:
return True
return False
expressions, but the string module is your friend in this case, and makes for very readable code, which is also unicode-ready, since string.(lower|upper)case also contain accented and other characters. Just do a dir(string) to see what other goodies there are...
Most of these are already available as methods of the str class and are
duplicated here only for backwards compatibility.
What's actually in string.lowercase/uppercase depends on the locale, you
should by no means take latin-1 for granted.
You have already withdrawn the unicode-ready claim.
Nasty, nasty, nasty :-)
Peter
On Thu, 02 Oct 2003 19:01:27 +0200, Peter Otten <__*******@web.de>
wrote: Christopher Koppler wrote:
Also, how would I check if [a-z] is not in a string?
import string
sometext = "whatever" if not string.lowercase in sometext: <do what you wanted to do>
Let's see:
import string sometext = "whatever" if not string.lowercase in sometext:
... print "do what you wanted to" ... do what you wanted to
I doubt that this is what you expected.
s1 in s2
tests if s1 is a substring of s2, but you want
def contains(s, chars): for c in s: if c in chars: return True return False
expressions, but the string module is your friend in this case, and makes for very readable code, which is also unicode-ready, since string.(lower|upper)case also contain accented and other characters. Just do a dir(string) to see what other goodies there are...
Most of these are already available as methods of the str class and are duplicated here only for backwards compatibility.
What's actually in string.lowercase/uppercase depends on the locale, you should by no means take latin-1 for granted.
You have already withdrawn the unicode-ready claim.
Nasty, nasty, nasty :-)
Peter
<High embarassement mode>
Big oops. Yeah, that goes to show what happens if you multitask
yourself and don't let your computer do it - I'm preparing for the
second of the two Oracle Certified Associate exams, which I take
tomorrow, and thought I'd take some time out and maybe answer some
questions here... Seems I'm a bit too confused and disorganized to do
that right now...
</HEM>
--
Christopher
Hank Kingwood <ha**@bogusaddress.xyz> wrote in message news:<e0******************@newssvr12.news.prodigy. com>... Also, how would I check if [a-z] is not in a string?
Thanks again, Hank
Hank Kingwood wrote: This is probably an easy question, but I can't find a function (maybe my syntax is off...) to search for [a-z] in a string. If someone would help out, I'd appreciate it!
Also, how would you recommend searching for the following in the same string: [a-z] [A-Z] [0-9] -
My approach would be to perform four separte checks, but I'm thinking there might be some cool approach that would use a dictionary or array. Ideas?
Thanks, Hank
Use regular expressions. import re any_string="find a-z, A-Z and 0-9, **+#-#?** no specials" re_search=re.compile(r'(\w+)') re_search.findall(any_string)
['find', 'a', 'z', 'A', 'Z', 'and', '0', '9', 'no', 'specials'] # Or re_search=re.compile(r'(\w)') re_search.findall(any_string)
['f', 'i', 'n', 'd', 'a', 'z', 'A', 'Z', 'a', 'n', 'd', '0', '9', 'n',
'o', 's', 'p', 'e', 'c', 'i', 'a', 'l', 's']
The **\w** means a-z plus A-Z plus 0-9 plus _.
If you doen't want to get the underline you have to define:
[a-zA-Z0-9] instead.
For more information read the docu for the re-module.
Regards
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Craig Bailey |
last post by:
Someone please explain what alternate universe I fell into this
afternoon when PHP started telling me that 2 doesn't equal 2.
Not sure about you, but when I run this, it tells me 59001.31 doesn't...
|
by: Askari |
last post by:
Hi,
How do for do a "select()" on a CheckButton in a menu (make with
add_checkbutton(....) )?
I can modify title, state, etc but not the "check state". :-(
Askari
|
by: Edward |
last post by:
The following html / javascript code produces a simple form with check
boxes. There is also a checkbox that 'checks all' form checkboxes
hotmail style:
<html>
<head>
<title></title>
</head>...
|
by: Steve Wylie |
last post by:
I am constructing an HTML questionnaire and one of the questions
requires people to rate some choices from 1 to 5, where 1 is their
favourite and 5 is their least favourite:
Car
Bus
Taxi cab...
|
by: pw |
last post by:
Hi, I need to create a function in javascript to check or uncheck all
checkboxes in a form. From what I understand, I can do this either by
specifying the name of the check box fields such as:
...
|
by: Tony Johnson |
last post by:
Can you make a check box very big? It seems like when you drag it
bigger the little check is still the same size.
Thank you,
*** Sent via Developersdex http://www.developersdex.com ***...
|
by: Chris Davoli |
last post by:
How do you enable a check box in the GridView. I selected Checkbox Field in
the Columns of the GridView, and the check box shows up in the Grid view, but
it is disabled. How do I enable it so I can...
|
by: Brian Tkatch |
last post by:
Is there a way to check the order in which SET INTEGRITY needs to be
applied? This would be for a script with a dynamic list of TABLEs.
B.
|
by: starke1120 |
last post by:
Im creating a check in – check out database for RF guns. I have a
table that contains models.
ID (primary key)
Model
A table that contains Gun Details
ID (primary key)
Model_id...
|
by: ghjk |
last post by:
my php page has 7 check boxes. I stored checked values to database and retrive as binary values. This is the result array
Array ( => 0 => 1 => 0 => 1 => 0 => 0 => 1 )
1 means checked....
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
| |