regex - Regular expression for matching the sentences with a specific symbol like % -


i want regular expression matching following sentence.

myfunc(l"try number 8 , value%s ",value); myfunc(l"but %s not true",word); myfunc(l"his name %s ",name); 

and on .

but don't want match sentences without % below

myfunc(l"it raining"); 

ie sentence having % should matched.i tried following patterns matchs sentences without % too.

myfunc[(l"(a-z)*(a-z)*(0-9)*(%)+(a-z)+(a-z)*(a-z)*(0-9)*(,)+(a-z)*(a-z)*(0-9))]    myfunc[(%)+] 

and

myfunc[(+(%)+)+] 

you don't need regular expression this... or if feel need use one, needs be, quite literally, "%".

why not try following instead?

if '%' in mystring:     ## have match! 

edit dsm's comment (and have said question has nothing python): updates looks want match whole thing, i.e. "func(...," percent sign in first argument, string. try following regex:

myfunc\(l\".*?%.*?\",[a-za-z]*\) 

or, restrict other characters in first parameter string alphanumerics , spaces, try this, little more robust above:

myfunc\(l\"[a-za-z0-9\s]*%[a-za-z0-9\s]*\",[a-za-z]*\) 

this ensure whole string matches function prototype shape, including "l" before string, "%" in string, , second alphabetical argument before closing bracket.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -