I wondered if someone could give me a brief primer on regular expressions. I’ve used regular expressions before, but when trying out regular expressions I find on the Internet, they often don’t work. I think the problem is that there are different kinds of regular expressions that work in different ways with different software programs.
For example, there’s “regular expressions,” and there’s GREP, which I’m not that familiar with. I work a lot with Dreamweaver, which has some regular expressions built into its search-and-replace function (though I seem to have lost them when I upgraded to version CC 2017). I also just bought BBEdit, which has GREP built in to it, though I haven’t yet worked with it.
Anyway, I’d like to start by asking what the main kinds of regular expressions are. There are apparently “regular expressions” and “GREP.” Are there any others I should know about?
And which combination of regular expressions and software would be the best choice for modifying content in some files in a folder?
For example, I have an index in an epub that has thousands of page numbers, each preceded by a space and followed by a comma, like this:
Africa 23, 179, 488,
Europe 25, 187,
I want to find a regular expression that will insert a particular hyperlink in a range of values (corresponding to a chapter or page file). For example, I would like to change everything from the page number 87 to 150 to something like this:
<a href="../Text/chapter2#" title="">87</a>,
<a href="../Text/chapter2#" title="">88</a>,
151, (unchanged, because it's not in the specified range of numerals)
I would later have to go back and manually insert the appropriate anchor values, of course.
To get to my question, what would you recommend as the best tools for doing this? Is GREP better than “regular” regular expressions? Would BBEdit be a better choice than Dreamweaver, or is there another software program that’s better still?
On a similar note, what’s the name of the PHP function that effectively acts like a regular expression when a page is previewed? For example, imagine your static text includes the words “New World.” You don’t want to modify this text, but you would like visitors to see “New World II” instead. You could obviously do this with a str_replace, but is there another PHP function that does this?
Thanks!
(I guess I should have posted that last question in the PHP forum, but I’ll leave it there for now.)