pythonregexpython-3.xnltknltk-book

Regular expression to match characters inside a word


I am doing the Pig Latin text conversion:

One of the requirements is putting qu together.

What I did re.findall(r'^qu', token)

but it only accepts qu together if the word/token starts with qu

If the word/token starts with aqu then it does not recognize qu together.

What I want is to recognize qu no matter the placement, including if it starts with Qu.

How do I fix this?


Solution

  • Remove the ^ from it, that cause this. The caret mean basically "start the matching from the beginning of the line (token in your case)".