last day (14 days later) » 

3:29 AM
1
A: Why is my regular expression combining capture groups from different lines

TomalakYour's (x mode): (?<prefix>\S*?)\h* (?<score>\d+[+-]?)\s* (?<suffix>.*?(?:[A-Z]{2}|\d{2})[A-Z]{2}\d{2}) (Probably) correct: ^ (?<prefix>(?=.*\b\d+["+-]?)\D+?)?\h* (?<image>\b\d+["+-]?)?\h* (?<suffix>\S*) http://regex101.com/r/sF2wV7/5

 
Wow, that was fast. Thank you. What is X mode?
 
x is the "ignore whitespace" flag, it allows you to break the regex over multiple lines and even add comments to it by treating all literal whitespace in the expression as irrelevant.
I'm not entirely sure about the regex yet. Take it with a grain of salt, I'm still tinkering on it.
 
Thanks for all help, really appreciate it.
 
@Mutuelinvestor I'm thinking version 5 should be pretty darn close. The key point is to use a look-ahead to make a subsequent image match a requirement for prefix. This way we can be unspecific about both prefix and suffix because we know that the image is the separator.
 
Could I trouble one last tine and ask that you break down your comment about the image match and look ahead. I'm a little out of my depth. Thanks again.
 
3:31 AM
@Mutuelinvestor Well, I thought: There is no way to prevent the prefix group from matching part of the suffix when the image is missing. So I made the image a requirement for the prefix to match at all.
You can do that with a look-ahead (?=.*\d+["+-]?)
 
Ok, I just read a little bit about look aheads now its starting to make sense to me
 
However this still falls flat because the image definition \d+["+-]? is too unspecific. The suffix can contain that sequence (and indeed it fails if the line contains a suffix only)
 
So how did you get around this.
 
In the string "vwu&ob12Ai18" the prefix group matches the "v" even though it should not, because the look-ahead catches the 12 and thinks that's the image.
I didn't
That's what I'm thinking about right now, but I think you have to tighten the definitions of how prefix, image and suffix can look like.
 
I have a specific document that define it. thesheets.com/symbol.pdf
 
3:36 AM
Having 3 successive groups that essentially all are optional match the empty string in the right order is tricky.
horse racing?
 
Is this a case where providing the detail on each capture group might be the way to go.
 
Yes but only if you can take it to a point where there is no longer an overlap between what makes prefix end and suffix begin. If there is always ambiguity that you don't need to bother being overly specific
For example, if you have "^15+vwu&ob12Ai18" then it's clear that 15+ is the image part.
but if you have "^15vwu&ob12Ai18"? Or is that not possible?
 
There's actually very little overlap between the Prefix and Suffix. They both can contain capital Gs and lower case Ss, otherwise no overlap.
The difference being the + sign. There's always a space between the Figure (image) and suffix, but otherwise the second case is possible.
 
Ooooh there is always a separator? I think I can work with that
What about the lines that contain prefix and image only? Then there is no space after the image, I suppose?
 
3:55 AM
There's actually a space most of the time, but not consistently.
 
What regex engine are you using, BTW? .NET?
 
I'm testing in Regex 101, but it will ultimately be in Excel VBA - sad but true.
 
actual VBA has no regular expression support. o_O
 
Actually it does. I was playing in it just today.
 
No, it doesn't. Unless you use VSTO, which is .NET
OK there is VBScript Regular Expressions module that you can use via COM in VBA, but VBA itself? No way.
 
4:04 AM
This is what I'm referring tohttp://stackoverflow.com/questions/22542834/how-to-use-regular-expressions-reg‌​ex-in-microsoft-excel-both-in-cell-and-loops
 
That's what I meant with "VBScript Regular Expressions module"
and that does not have the ability to use named groups, or x mode or quite a few other advanced regular expressions features, so it's rather important to know
 
Yes, it seems to have everything in your version 5 except the \h
I don't have to name the groups.
 
Yes, \h is not supported either, but you can substitute that with [ \t]
I'm still tackling the problem of preventing the image part to match against "vwu&ob12Ai18"
 
ok, really appreciate it. Hope I can return the favor sometime.
 
That's all-right.
Mainly because if you define image as "either followed by a space or is the last thing on the line (i.e. no suffix)"
because with that definition it could still match the 18 in that sample
 
4:14 AM
Tough nut to crack.
 
there is no space required between prefix and image, right?
 
4:52 AM
I think I finally have something that works
@Mutuelinvestor Of course you must collapse the expression into one line
Other things to do: Add a space at the end of the line before you match it.
Trim the contents of the groups before use.
 

last day (14 days later) »