Please read: This question is about regex, but I’m not sure regex is the best solution. I haven’t posted an example of the code I have so far, but I want the reader to know that I am working very hard on solving this myself. I don’t want to put the idea into people’s head that regex is the best way to go because it may not be. I’ve been told by some programmers, already, that regex is not the best place to start. Other programmers have told me that my other solutions are not good, either. So, if regex is wrong, please show me what is right.
Example of input
vulture (wing) tabulations: one leg; two legs; flying father; master; patriarch mat (box) pedistal; blockade; pilar animal belly (oval) old style: naval jackal's belly; jester slope of hill (arch) key; visible; enlightened
Basically, I’m having trouble with some more complicated regex commands. Most of the code I’m finding that uses regex is very simple, but I could use it in so many places if I could get good with it. Would you look at the kind of stuff I’m trying to do and see if you can convert any of it?
- Arrayize the word or words between the braces, “(” and “)”.
- Arrayize the first words following a new line ending xor four spaces and then a closing brace, “)”, and a space and an open brace " (" AND the first words in the document up until a space and an open brace " (".
- On any line with semicolons, arrayize the words which are separated by semicolons. Get the word or words after the last semicolon but do not get the words after a line break or four consecutive spaces. Words from lines that begin with the string “tabulations:” should not be included in this array, even though lines that begin with the string “tabulations:” have semicolons on them. If a new line ending in a close brace, “)” comes before a line containing semicolons and not starting with “tabulations” “no alternates” to the array, instead.
- Get the word or words following the colon and preceding the line break on a line that begins with the string “old style:”. If a new line ending in a close brace, “)” comes before a “tabulations:”-starting line, add “no old style” to the array, instead.
- The same as 3, except only for lines that begin with the string “tabulations:”. If a new line ending in a close brace, “)” comes before a “tabulations:”-starting line, add “no tabulations” to the array, instead.
I am trying to figure out how to do this via PHP because I use the data in a PHP form, and because PHP and Javascript are the only scripting languages I am familiar with and PHP seems most viable in this situation.