3

This question is an expanded question of this : How to replace QRegExp in a string?

In that question, problem is solved. But now I need to use QRegularExpression instead of QRegExp. How should I transfer the answer of Toby Speight?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
songvan
  • 369
  • 5
  • 21
  • 1
    What have you tried? In particular, what makes you think that simply replacing `QRegExp` with `QRegularExpression` won't work in this case (with the proviso you change `Qt::CaseInsensitive` to `QRegularExpression::CaseInsensitiveOption`)? – G.M. Sep 14 '18 at 10:14
  • @G.M.: thanks for your answer, Actually that is what i am looking for. I dont know how to replace `Qt::CaseInsensitive` in `QRegularExpression`. :) – songvan Sep 14 '18 at 12:37
  • But G.M. said exactly what to replace it with: `QRegularExpression::CaseInsensitiveOption`, it's of type `QRegularExpression::PatternOption`. – Kuba hasn't forgotten Monica Sep 14 '18 at 16:46
  • @KubaOber: yeah, his answer solved my problem already. – songvan Sep 18 '18 at 06:57
  • Please consider finalizing the question if the answer below works for you. – Wiktor Stribiżew Apr 18 '20 at 13:33

2 Answers2

2

QRegExp case insensitive search mode is enabled with Qt::CaseInsensitive.

When you use QRegularExpression that is based on PCRE regex engine, you may use QRegularExpression::CaseInsensitiveOption:

The pattern should match against the subject string in a case insensitive way. This option corresponds to the /i modifier in Perl regular expressions.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
1

In python, it's:

re = QRegularExpression(pattern, QRegularExpression.CaseInsensitiveOption | QRegularExpression.DotMatchesEverythingOption)

And if you need 2 options

re = QRegularExpression(pattern, QRegularExpression.CaseInsensitiveOption | QRegularExpression.DotMatchesEverythingOption)

buddemat
  • 4,552
  • 14
  • 29
  • 49
QuentinJS
  • 162
  • 1
  • 9