Regex question

J

Jonas Galvez

I've a perhaps unusual piece of data to parse with regexes.
['h']

This is a very very very simplified example. The result I was
expecting is the following: ['a', 'b', 'c'] ... and so forth. Is it
impossible to repeat a pattern group inside another?


Tia,



\\ jonas galvez
// jonasgalvez.com
 
L

Luke

Jonas said:
I've a perhaps unusual piece of data to parse with regexes.


['h']

This is a very very very simplified example. The result I was
expecting is the following: ['a', 'b', 'c'] ... and so forth. Is it
impossible to repeat a pattern group inside another?

Are you hoping for your regular expression to match the whole string, or
just one letter? This is how I would get the result you seek:
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']

The regular expression you used, "a (\w ?)*", will match the whole string,
which is why you have only one element in the list returned by findall.
Since you used a group (using parentheses), findall only returned what was
inside the group (the 'h') rather than the whole match ('a b c d e f g h').
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Stupid Regex Question 2
Regex not matching a string 2
compound regex 0
JavaScript Regex 19
regex object limitations/behavior for large regexes? 1
regex question 11
Convert AWK regex to Python 6
Question on regex 1

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top