Thanks!
A:
Your first question is asking for a "smart" way of writing out a regular expression which is possibly quite hard. That's what you get for using the "w" mode.
The "w" (word) mode is not really a very good regex mode. It's regexp
whitespace mode is pretty weird and only works on a couple of regexp
engines (Perl and PCRE). The problem is that it will do some
extra processing on matching patterns to try to make them faster. But
these changes break the semantics of regexp which can lead to some very
very confusing bugs.
I strongly advise you to read Perl's regexp tutorial before attempting
to write your own regexp.
Now to answer your questions:
why are all these numbers? :?
You must use the "s" (singleline) mode. See the Perl regexp tutorial for an explanation of why.
After I am done, how do I save it in the XML?
When you use the "s" mode, you should probably create a pre-defined XML file with the matching rules, then write the rules to the XML file one rule at a time and simply loop over all the rules. That way the XML file will be small and easy to create and update.
The other solution is to create a program that reads the rules out of the XML file and writes out the matching rules.
why is it not working as it did when i used the other syntax?
The "s" mode only allows a single string on the left side of the expression. This means that
(.*) + (.*) + (.*)
is not valid and will never match.
The other problem is that there are regexp rules in the regexp rules file that don't match what you want. See the Perl regexp tutorial for more information.
if i put the "w" in "g" mode, it works, but then it does not repeat
Of course it won't repeat, the problem is that the engine doesn't have
to parse the whole string again. That's why the "s" mode is better.
how do i save the regexp rules in a file so that i can use it later?
That's what you want to do. There is no "one-size-fits-all" solution to this problem.
Related links:
Comentários