python - Get text in specific text? -


How do I get text within a particular lesson? Like, if I have such text:

'lololol \ r asdfasdf r \ gfhfgr'

I call it 'asdfasdf'. Basically, bits '\ r' and 'r' '?

one more solution,

  import re s = r Lololol \ r asdfasdf r \ gfhfgr 'pattern = re.compile (' \\\\ 'R (. *?) R \\\' ') Print pattern. Fondol (s)   

['asdfasdf']

edit:

Well, friend , What you said is that you wanted in your example. If you want, you are welcome to use

  pattern = re.compile ('\\\\ r (. *?) R \\\' ')   

which will give you instead of ['asdfasdf'] .

'All slash' is required because of Python and re-parse strings; A slash is used as the escape character for the defrift, such as \ n (new row). To denote a slash, try print ('\\') to see if you must use the \\ digraph.

Then you want to repeat it, because again your set of diagrams (\, \ for whitespace, etc.). So if you enter '\\\\' ', then understand it to be a string made of two slashes, \\ , which returns it again , Who parses it and thinks that you are searching for a single \ character.

Sometimes you can do without it; If you have a string like '\ m' , where the previous char is not in a valid digraph, the result is actually a two-letter string \ m ( Try print ('\ m') ). \ R is kind of cowardly; Python recognizes it as a carriage-return digraph, but again does not use \ r as a diagram, so both Python '\ r' or '\\ r' resulted in a rectangular string '\ r Looking for 'I like double-double-slash, because it means that you do not have to remember two different definitions that are legal or not! On the other hand, the dragon and then both recognize the same quote mark ( print ('\') a ' character) - so both slashes are To completely avoid double or you'll get one "hey, where is the rest string ??" Error ('string not finished').

The second option is to enter the raw string ( r'abc '); It does not tell the python to parse the diagram in the string, but it will still do so, so that your pattern is

  pattern = re.compile (r '\ \ (r *. * ?) R \\ ')    

Comments