RegEx question.
I found some ways to get things in a string with the RegEx example.
Prelude:
When I want to add a new feature in a running project, I create a brand new project and build a prototype. In this case, I only add a ListBox in that project and teh code is in Window1.Open. I keep in mind the environment where the code will be pasted later. That is why I set the search string: in the main project (see the screen shot), the search string is a file name read from a folder. *
The string to search in is:
“Star Trek - The Next Generation 02 - [huckyc] [2012-01-15] (Miss page 15).7z”
How to get the date (SQLDate format):
Search Pattern: “\d\d\d\d-\d\d-\d\d”
Found string: 2012-01-15
How to get a word with 10 characters:
Search Pattern: “\w\w\w\w\w\w\w\w\w\w”
Found string: Generation
How to get text between two html tags ?
Just read the doc and you will be far more than happy.
Unfortunately, I do not found a way to get text between brackets (huckyc is just an example, I have many other available data string, not always the same length.
Also, I was unable to find the information between parens ‘(’ and ‘)’.
Any help is welcome.
Of course, I can search specifically using InStr or NthField for these, but when will I learn to use RegEx.
Worst, I started with RegEx searching the SQLDate from my search string and it tools me only minutes to do so. Now, after 4 hours (3:16AM to 7:45AM) I do not have advanced by a single bit !
(excepted for the search a word who is i characters long !)
I FOUND SOMETHING:
Search Pattern: “\x28.\x29" or "\(.\)”
Found string: (Miss page 15)
But how do I exclude the open and close parens ?
8:00 AM discovery:
Search Pattern: “\[.*\]”
Found string: [huckyc] [2012-01-15]
I remember I read something to avoid to get from first [ to the last ] in the docs.
I got it ! I got it ! I just have to be a bit greedy !
Search Pattern: "\\[.*?\\]"
Found string: [huckyc]
BTW: I still get the useless [] and ().
The question now is: How can I remove them (beside using a Mid() function) ?
Here is a screen shot of what I am actually doing:
Yes, we can have more than two background colors on a ListBox. As you may understand, it is the missing of an icon on Column 0 that displays a magenta background.
Also, Lines that have a SQLDateTime does not have a date in their file names.
At last, you can see the enclosed strings in columns Scanner and Warning.
- I just realize that in fact, this is the second spin off for the main project: how to use RegEx to set data into a project who displays how to report data from a folder full of files who is in fact a spin of of a larger folder !