python - change string during pyparsing -


In my pyparsing code I have the following expressions:

  exp1 = literal ( "foo" ) + pressing (literally ( "=")) + words (alphanums + '_-') exp2 = literal ( "foo") + press (literally ( "! =")) + words (alphanums + '_-') Exp = optional (exp1) & amp; Optional (exp2)   

I want to change the foo from bar to exp2, so that I'm in perced data = and! Is it possible to differentiate between =?

The comments of Karl Connectchtel are valid, but you do not want to change a token Pars can do this in action

  def changeText (s, L, T): .. Return "boo" + t [0] expr = literal ( 'A') setParseAction (changeText) + "B" print expr.parseString ( "AB"). AsList ()   

will be printed:

  [ 'booA', 'b']   

If you continue If you want to change the expression with the literal string, then replace :

  expr = literal (".") SetParseAction (replaceWith ("A to Z")) + 'B' print expr.parseString ("AB") asList ()   

Print:

  ['Z', 'B']    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -