Honest, I did not get what you were trying to say (still don't really). Are you trying to parse text that contains patterns like this?
"This is my pattern x:0123456789 and I want to get the 0123456789"
If that is the case, what if the text contains something like this?
"This has an x:0123 but there is a blank. Do I just take the next 10 characters or do I stop at the blank, or is this not a match?"
"This does not have enough characters after the pattern. Should it match x:1234"
"These patterns overlap. Should they count? x:123 y:4657"
And I really don't get what do you mean by "group them"? Do you want a regex that looks for "x:", "y:" or "z:"? You could do that with [xyz]:\w{10}
1 2 3 4 5 6 |
import re
text = "this is x:0123, some things y:0123456, that may or may not z:0123456789, match the pattern x:abcdefghijk, y:123 z:4567"
pattern = re. compile ( "[xyz]:\w{10}" )
print (re.findall(pattern, text))
|
Output:
['z:0123456789', 'x:abcdefghij']
This grabs the two strings that start with x:, y: or z: and are followed by 10 non-whitespace characters.
If changed to just grab the next 10 characters, it does this:
1 2 3 4 5 6 |
import re
text = "this is x:0123, some things y:0123456, that may or may not z:0123456789, match the pattern x:abcdefghijk, y:123 z:4567"
pattern = re. compile ( "[xyz]:.{10}" )
print (re.findall(pattern, text))
|
Output:
['x:0123, som', 'y:0123456, t', 'z:0123456789', 'x:abcdefghij']
Now I get all the x:, y: and z:'s that are followed by 10 characters and don't overlap with another pattern.
['x:0123, som', 'y:0123456, t', 'z:0123456789', 'x:abcdefghij', 'y:123 z:4567']
Note that z:4567 at the end does not count as a match because z: is not followed by 10 characters.
And what did you mean by this?
1 2 3 |
varX = “x: “
varY = “y: “
varZ = “z: “
|
Is varY supposed to be a variable referencing the "y:" pattern, or is it a variable used to reference the 10 characters following "y:" in the text you are searching?
If your posts on the Arduino forum are this vague I understand why you get more questions than answers. Remember, you have all the details and we know nothing except the info in your post. Write posts as though the audience has no idea what you are talking about, because that is True. My favorite format is "Here is my input, this is my expected output, additional information." Then I can test my reply against the input and output to see if I'm answering the question correctly. If you can't do that, provide lots of details. Details are important, especially with something like regular expressions where two patterns that look almost the same will give radically different results.