if i have a string, let's say its
xx = 'abc123def456ghi"
i'm having problems figuring out a way to know if xx[0] is a letter or number, then check xx[1] for the same thing and so on and so forth.
what i thought would be easiest is doing somethign through regex
have
pattern1 = re.compile('[a-z]')
pattern2 = re.compile('[0-9]')
can i make a loop that check something like... -
j = 0
-
while j < len(xx):
-
if j == pattern1:
-
print "its a letter"
-
2 1153 bvdet 2,851
Expert Mod 2GB
if i have a string, let's say its
xx = 'abc123def456ghi"
i'm having problems figuring out a way to know if xx[0] is a letter or number, then check xx[1] for the same thing and so on and so forth.
what i thought would be easiest is doing somethign through regex
have
pattern1 = re.compile('[a-z]')
pattern2 = re.compile('[0-9]')
can i make a loop that check something like... -
j = 0
-
while j < len(xx):
-
if j == pattern1:
-
print "its a letter"
-
You can also do something like this: - import string
-
-
xx = 'abc123def456ghi>'
-
-
for letter in xx:
-
if letter in string.ascii_letters:
-
print '"%s" is a letter' % letter
-
elif letter in string.digits:
-
print '"%s" is a digit' % letter
-
else:
-
print '"%s" is neither a letter or a digit' % letter
-
>>> map(str.isalpha,xx)
-
[True, True, True, False, False, False, True, True, True, False, False, False, True, True, True]
-
>>> zip(xx,map(str.isalpha,xx))
-
[('a', True), ('b', True), ('c', True), ('1', False), ('2', False), ('3', False), ('d', True), ('e', True), ('f', True), ('4', False), ('5', False), ('6', False), ('g', True), ('h', True), ('i', True)]
-
>>>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: aeuglein |
last post by:
Hello!
I have this RegEx:
/(+:\/\/+)/i
Now, I want to exlude on the end of a String the formats .gif / .jpg /
..png / .exe / .zip / .rar
How I can this add to my regex ?
|
by: mikea59 |
last post by:
I am getting errors in XMLSpy (Pro) in the following case:
Source Document:
<test> 12345 AB 12345 </test>
Stylesheet:
<xsl:stylesheet version="2.0"...
|
by: Day Of The Eagle |
last post by:
Jeff_Relf wrote:
> ...yet you don't even know what RegEx is.
>
I'm looking at the source code for mono's Regex implementation right
now. You can download that source here ( use the class...
|
by: alphatan |
last post by:
Is there relative source or document for this purpose?
I've searched the index of "Mastering Regular Expression", but cannot
get the useful information for C.
Thanks in advanced.
--
Learning...
|
by: bill tie |
last post by:
I'd appreciate it if you could advise.
1. How do I replace "\" (backslash) with anything?
2. Suppose I want to replace
(a) every occurrence of characters "a", "b", "c", "d" with "x",
(b)...
|
by: Kofi |
last post by:
Any takers?
Got a string of DNA as an input sequence GGATGGATG, apply the simple
regex "GGATG" as in
Regex r = new Regex("GGATG", (RegexOptions.Compiled));
MatchCollection matches =...
|
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: CB |
last post by:
Trying to match the entire following object literal code using a RegEx.
var Punctuators = { '{' : 'LeftCurly', '}' : 'RightCurly' }
Variations on the idea of using /var.*{.*}/ of course stops...
|
by: Tidane |
last post by:
Visual Basic.NET Framework 2.0
I've created a program to parse out text as the program recieved it and use Regex matching to decide what should be done. My problem is that the text is matching when...
|
by: pedrito |
last post by:
I have a regex question and it never occurred to me to ask here, until I saw
Jesse Houwing's quick response to Phil for his Regex question.
I have some filenames that I'm trying to parse out of...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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: 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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |