Subscribe^FREE.*(books|degree|sex)a+[0-9]*\s+.*Then get some data that this regexp is being used for, and write your own little simulator program, sticking parentheses into the regexp (I'm making this syntax up):
exp = new Regexp ( "(a+)([0-9]*)(\s+)(.*)" );
testString = "Green eggs and ham aaa0293 super!";
matchInfo = exp.matchAgainst ( testString );
if ( matchInfo.matches() ) {
for ( i = 0 to matchInfo.matchPartCount(); i++ ) {
part = matchInfo.matchPart(i);
print ( "Part " + (i+1) + ", len " + part.length() + ": " + part );
}
} else {
print ( "Does not match" );
}This program would print out:Part 1, len 3: aaa
Part 2, len 4: 0293
Part 3, len 5:
Part 4, len 6: super!Then fiddle around with the input string a little at a time, seeing what how changes affect the data that's matched, or even whether it's matched at all.# Define regexes to match main quiz result line and folded title/author lines
re_word='[^ ]+' #run of nonspaces
re_words="$re_word( $re_word)*" #words separated by at most one space
re_num='[0-9.,]+' #run of digits, points or commas
re_voice="^ +(#?)" #leading spaces, optional hash
re_quiz_no="($re_num) +" #number, trailing spaces
re_lang="(EN|SP) +" #at least two trailing spaces
re_title="($re_words) +" #words with two or more trailing spaces
re_author="($re_words) +" #words with trailing spaces
re_il="(LG|MG|UG) +"
re_bl="($re_num) +" #number with at least one trailing space
re_points="($re_num) +" #same again
re_wcnt="($re_num) +" #same again
re_fnf="($re_word)$" #word at end of line
re_quiz="$re_voice$re_quiz_no$re_lang$re_title$re_author$re_il$re_bl$re_points$re_wcnt$re_fnf"
re_title2="($re_words) " #alternate pattern: only one trailing space
re_author2="($re_word,( $re_word)*) +" #alternate pattern: word, comma, maybe more names, spaces
re_quiz2="$re_voice$re_quiz_no$re_lang$re_title2$re_author2$re_il$re_bl$re_points$re_wcnt$re_fnf"
re_ext_title="^ {17,19}($re_words)$"
re_ext_author="^ {62,71}($re_words)$"
re_ext_title_author="^ {17,19}($re_words) +($re_words)$"
^ +(#?)([0-9.,]+) +(EN|SP) +([^ ]+( [^ ]+)*) +([^ ]+( [^ ]+)*) +(LG|MG|UG) +([0-9.,]+) +([0-9.,]+) +([0-9.,]+) +([^ ]+)$which is really no fun at all. I am a coder, and I wouldn't like having to do that for a living.
' Define regex patterns to match main quiz result line and folded title/author lines
repWord = "[^ ]+" ' run of nonspaces
repWords = repWord & "( " & repWord & ")*" ' words separated by at most one space
repNum = "[0-9.,]+" ' run of digits, points or commas
repVoice = "^ +(#?)" ' leading spaces, optional hash
repQuizNum = "(" & repNum & ") +" ' number, trailing spaces
repLang = "(EN|SP) +" ' at least two trailing spaces
repTitle = "(" & repWords & ") +" ' words with two or more trailing spaces
repAuthor = "(" & repWords & ") +" ' words with trailing spaces
repIL = "(LG|MG|UG) +"
repBL = "(" & repNum & ") +" ' number with at least one trailing space
repPoints = "(" & repNum & ") +" ' same again
repWdCnt = "(" & repNum & ") +" ' same again
repFnf = "(" & repWord & ")$" ' word at end of line
set reQuiz = new regexp
reQuiz.pattern = repVoice & repQuizNum & repLang & repTitle & repAuthor & _
repIL & repBL & repPoints & repWdCnt & repFnf
repTitle2 = "(" & repWords & ") " ' alternate pattern: only one trailing space
repAuthor2 = "(" & repWord & ",( " & repWord & ")*) +" ' alternate pattern: word, comma, maybe more names, spaces
set reQuiz2 = new regexp
reQuiz2.pattern = repVoice & repQuizNum & repLang & repTitle2 & repAuthor2 & _
repIL & repBL & repPoints & repWdCnt & repFnf
set reExtTitle = new regexp
reExtTitle.pattern = "^ {17,19}(" & repWords & ")$"
set reExtAuthor = new regexp
reExtAuthor.pattern = "^ {62,71}(" & repWords & ")$"
set reExtTitleAuth = new regexp
reExtTitleAuth.pattern = "^ {17,19}(" & repWords & ") +(" & repWords & ")$"
You are not logged in, either login or create an account to post comments
posted by the dief at 4:08 AM on May 12 [1 favorite]