Page 1 of 1

Regex to Find Words Near Other Words

Posted: 30 Nov 2016 01:33
by Dustydog
I got a little irritated the other day at the limitations of CHM format files. So, I unzipped the html, turned them into plain text, then combined and edited them, and then used this little regex (among others) to help find what I'm looking for. It's also useful, of course, finding things using XY either in content or in filenames with the search feature.

\bword1(?:\W+\w+){0,6}?\W+word2\b

Substitute the "6" for however many words you wish to constrain the forward search by, and substitute word1 and word2 exactly in those positions. If you wanted to add separate by at least so many words, change the "0".

(All hail to Jan Goyvaerts for this regex (and his tutorials, and his software). There's also a version of this regex where you use alternation to also find the words in reverse sequence, but this is the most useful to me, and the easiest to understand.)

***

The utilities I use to extract and combine CHM files, if you're interested, are 7-zip to unzip the CHM, then HTMLAsText from NirSoft (a very reliable company for free utilities - you should browse their site if you never have), and then Mr. Goyvaerts' (of Just Great Software) EditPad - either pro or lite (free, no strings) because of its beautiful regex support and a raft of other great features. Notepad++ would work too, ofc. One important regex to run, imho, is one that deletes duplicate lines as there tend to be a lot of them due to the html hierarchy. Again, EditPad works very well with such things.

PS

I wish there were a comprehensive PDF I could search through instead for XY's help.

Re: Regex to Find Words Near Other Words

Posted: 30 Nov 2016 02:22
by highend
I wish there were a comprehensive PDF I could search through instead for XY's help
https://www.xyplorer.com/download/XYplorerHelp.pdf

Re: Regex to Find Words Near Other Words

Posted: 30 Nov 2016 20:33
by Dustydog
Well, as usual, I feel really, really stupid about half the time I post something here. I actually had that bloody file.

I'll keep the post up, embarrassment and all, because I've found the technique useful elsewhere when a PDF or Word file doesn't exist - and not everyone has access to a good tool that can do a flexible PDF GREP, and it's simply a broadly useful regex that someone who doesn't really know how to write them might find useful.

I also find it useful to create a text file of a help CHM for the purposes of inserting my own notes from forums, searches, etc. (And comment things that I consistently forget in terms of syntax or whatever.) I simply tag the comments consistently so that it's easy for a regex to find in a personal system I've worked out. I also include search terms that I tend to think of that are kind of synonyms for the correct search term. I also find text-based more useful than marking up the PDF as a PDF and easier to access my notes from all devices and bits of software. I also zap material that I don't need. And yes, all that can be done from a PDF as well, but it takes more complicated software. There are of course good PDF to text converters - Word will even do it. But I find this simple and sufficient.

An issue I keep encountering is things that I used to do, or know how to do in another way - there's simply a better, faster way to do it within XY. (And thanks for the PDF I forgot about and didn't turn up on my first Google search. :S)

***

I should have a tagline that says: I think I remember missing my memory. :oops: