Frage

How can I use QRegExps to find each item in a list? What I am trying to do is to get each team in a list. They must be separated by a comma or a comma and space. For example, I want to get each team in this list:

    Patriots, Celtics, Red Sox

My initial regular expression was:

    [^, ]+

There is a problem with this because teams are allowed to have space characters in them, such as the Red Sox. Another one I tried was this:

    [^,] +

But that caused problems because it grabbed the space after the comma, and appended it to the beginning of the name of the following item in the list.

Any solutions?

War es hilfreich?

Lösung

list = str.split(QRegExp(",\\s+"));

Or, when whitespaces are optional:

list = str.split(QRegExp(",\\s*"));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top