Looking at a file of text, where I want to match, it is delimited with single-quotations, but zero or One might have escaped single-quote, plus zero or more tabs and newline characters (not run) - I just want to match text. Example:
menu_item = 'casserole'; Menu_item = 'Fry the meat'; Menu_item = 'Tony' magic pizza '; Menu_item = 'hamburger'; Menu_item = 'Dave's Famous Pizza'; Menu_item = 'Dave's less known Gyo'; I want to capture only the text (and empty space) by ignoring tabs / newlines - and I really do not care if the saved quote appears in the results, unless It does not affect the match:
Casserole meat loam Tonys magic pizza hamburger Daves famous pizza Dave is less well known gyro # I have managed to create a regex that almost does this - it handles the quotes saved, but not the new lines: < Pre> MenuPat = r "menu_item = \ '(. *) (\\\')? (\ T | \ n) * (. *) \ '" InFP.readlines () for the line: m = Re.search (MenuPat, line) If m does not have any: print m.group () Definitely there is a regular expression of a ton of questions - but most of Pearl's Are using, and if there is one what I want, I understand it I'm not able to :) :) And since I'm using Python, I do not care that it has spread to many groups, it's easy to reconnect.
Some answers have just asked to go with the code to parse the text though I'm sure I can do this - for the reggax I'm working on shut down ) and it seems that should be. UPDATE: I realized that I'm doing a Python scripts () to get each line, which is clearly breaking lines that are for reggae Has been there. I am looking to rewrite it, but any suggestion on that part would also be very useful.
should do this:
menu_item = '((?: [^ '\\] | \\') *) ' here (?: [^' \\] | \\ ') * part < Code> ' and \ or match any sequence of any character other than one word style \' . [^ '\\] also allows line breaks and tabular which you need to replace by a space.
Comments
Post a Comment