Jump to content

Recommended Posts

Posted (edited)

@kyl : your pattern is correct with the OP string. When you try it with the string suggested by Mikell in his first message (where line 4 contains only 3 numbers), the expected result might be wrong after the conversion to 2D array. For this reason, I tried to explain that a regex with 4 capturing groups will always return an array size divisible by 4.
Sorry if my explanation is not clear enough (my english is not perfect yet)... :'(

Edit : @kyl, I see that you are becoming a big fan of regex (and you have made good progress in recent months)

Edited by jguinch
Posted

@jguinch - The example with the last line containing 3 numbers was from my post and was for the purpose of illustration only.  That being said, I quite agree that

method is very restrictive.

@kyl, I see that you are becoming a big fan of regex (and you have made good progress in recent months)

Thanks, just when I think I've got it, one of you heavy hitters come along with an eye-popper that makes me go "wow" or "shit" or both.  But, I'm too stubborn to give up... 

 

 

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

:lol: Well, I have the same problem (I work hard to overcome). Each of us think differently and we do not see all the things in the same way. (for example, jchd can record 150 lines of hexadecimal characters in his head just by looking at the screen during 3 seconds, so regex seems easy for him :D)

In fact, my explanation is not really good, because a capturing group with ? or some more complex patterns will not return a result for each capturing group... But the code I provided, it should do the trick

Posted

kylomas,
The lines provided by the OP show 4 numbers - (n,n) (n,n) style - it looks a lot like coordinates or so
Then removing lines which are empty or not in this 'correct' number style (which I named 'non valid') could be a judicious approach  :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...