Is it possible to match components of a string with the pattern ((length)(text with given length))+ with regular expressions?

For example:

06Watcha05Gonna02DoABCDEFG

It comprised of:

  • a 6 letter text (Watcha)
  • a 5 letter text (Gonna)
  • a 2 letter text (Do)
  • Misc text

Posted Apr 17, 2020, 7:03 AM UTC

14
_n69s_•

I don't understand what you're trying to say.

1
PoeStudent•

I understand the numbers before the word but what throws me off is the ABCDEFG, what exactly are you trying to do?

1
[deleted]•

[deleted]

1
PoeStudent•

Sorry I'm still a little confused.

Are you trying to get information from this string

12345678900120010099QQ14Java in Action098765432109876543210110001099QQ08Calculus

and format it into this?

1234567890          // ISBN 
0120                // MM-YY date 
010099              // $100.99 
QQ                  // Magic String 
14                  // Length of the book name 
Java in Action      // Book name 
0987654321          // ISBN 
0110                // MM-YY date 
001099              // $10.99 
QQ                  // Magic string 
08                  // Length of book name 
Calculus            // Book name

​

Or are you trying to do the opposite of that?

1
CodeImplementation•

Perhaps it would be easier to understand what you're looking for if you could give us a few examples of strings which should match and some which shouldn't.

1