View Single Post
Old 07-20-2011, 04:23 AM   #83
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,522
Karma: 8065528
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by burbleburble View Post
- I need to be able to match such a sentence, without the tags getting in the way. Unfortunately, regex that I know of doesn't support repeating strings, only characters: I can't write (<[^>]>)*.. and then there would still be the problem of gathering all the variable amount of matches (\1=Bob , \2= went to, etc... in this case)
Regular expressions match sequences of characters. There is no standard way to match repeating character sequences. A favorite assignment to give students is to write a regular expression that matches arbitrary palindromes (a string that matches itself from the outside in, such as ABCDCBA). The correct answer is "You can't." What you want to do is similar, with the same answer.

In some regexp systems you can use back references to match what you matched before, but in limited ways such as fixed counts. In others you must use programmatic matching (in effect, recursive regexps) to dynamically modify the regexp. This latter scheme can be used to solve the palindrome problem. It is, however, very system dependent and rather complicated.

If you have a limited number of cases, it would probably be easier to code these using string functions instead of regexps. That way you can handle both arbitrary numbers of matches and the necessary recursion.

What does javascript have to do with this? Are you really running javascript inside a calibre (python) plugin?
chaley is offline   Reply With Quote