7#ifndef QREGULAREXPRESSION_H
8#define QREGULAREXPRESSION_H
10#include <QtCore/qglobal.h>
11#include <QtCore/qstring.h>
12#include <QtCore/qstringview.h>
13#include <QtCore/qshareddata.h>
14#include <QtCore/qvariant.h>
22class QRegularExpressionMatch;
23class QRegularExpressionMatchIterator;
25class QRegularExpression;
27QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QRegularExpressionPrivate, Q_CORE_EXPORT)
29Q_CORE_EXPORT size_t qHash(
const QRegularExpression &key, size_t seed = 0)
noexcept;
35 NoPatternOption = 0x0000,
36 CaseInsensitiveOption = 0x0001,
37 DotMatchesEverythingOption = 0x0002,
38 MultilineOption = 0x0004,
39 ExtendedPatternSyntaxOption = 0x0008,
40 InvertedGreedinessOption = 0x0010,
41 DontCaptureOption = 0x0020,
42 UseUnicodePropertiesOption = 0x0040,
47 Q_DECLARE_FLAGS(PatternOptions, PatternOption)
49 PatternOptions patternOptions()
const;
50 void setPatternOptions(PatternOptions options);
53 explicit QRegularExpression(
const QString &pattern, PatternOptions options = NoPatternOption);
54 QRegularExpression(
const QRegularExpression &re)
noexcept;
55 QRegularExpression(QRegularExpression &&re) =
default;
56 ~QRegularExpression();
57 QRegularExpression &operator=(
const QRegularExpression &re)
noexcept;
58 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRegularExpression)
60 void swap(QRegularExpression &other)
noexcept { d.swap(other.d); }
62 QString pattern()
const;
63 void setPattern(
const QString &pattern);
67 qsizetype patternErrorOffset()
const;
68 QString errorString()
const;
70 int captureCount()
const;
71 QStringList namedCaptureGroups()
const;
75 PartialPreferCompleteMatch,
76 PartialPreferFirstMatch,
81 NoMatchOption = 0x0000,
82 AnchorAtOffsetMatchOption = 0x0001,
83 AnchoredMatchOption Q_DECL_ENUMERATOR_DEPRECATED_X(
84 "Use AnchorAtOffsetMatchOption instead") = AnchorAtOffsetMatchOption,
85 DontCheckSubjectStringMatchOption = 0x0002
87 Q_DECLARE_FLAGS(MatchOptions, MatchOption)
90 QRegularExpressionMatch match(
const QString &subject,
92 MatchType matchType = NormalMatch,
93 MatchOptions matchOptions = NoMatchOption)
const;
95#if QT_DEPRECATED_SINCE(6
, 8
)
97 QT_DEPRECATED_VERSION_X_6_8(
"Use matchView instead.")
98 QRegularExpressionMatch match(QStringView subjectView,
100 MatchType matchType = NormalMatch,
101 MatchOptions matchOptions = NoMatchOption)
const;
105 QRegularExpressionMatch matchView(QStringView subjectView,
106 qsizetype offset = 0,
107 MatchType matchType = NormalMatch,
108 MatchOptions matchOptions = NoMatchOption)
const;
111 QRegularExpressionMatchIterator globalMatch(
const QString &subject,
112 qsizetype offset = 0,
113 MatchType matchType = NormalMatch,
114 MatchOptions matchOptions = NoMatchOption)
const;
116#if QT_DEPRECATED_SINCE(6
, 8
)
118 QT_DEPRECATED_VERSION_X_6_8(
"Use globalMatchView instead.")
119 QRegularExpressionMatchIterator globalMatch(QStringView subjectView,
120 qsizetype offset = 0,
121 MatchType matchType = NormalMatch,
122 MatchOptions matchOptions = NoMatchOption)
const;
126 QRegularExpressionMatchIterator globalMatchView(QStringView subjectView,
127 qsizetype offset = 0,
128 MatchType matchType = NormalMatch,
129 MatchOptions matchOptions = NoMatchOption)
const;
131 void optimize()
const;
133 enum WildcardConversionOption {
134 DefaultWildcardConversion = 0x0,
135 UnanchoredWildcardConversion = 0x1,
136 NonPathWildcardConversion = 0x2,
138 Q_DECLARE_FLAGS(WildcardConversionOptions, WildcardConversionOption)
140 static QString escape(
const QString &str)
142 return escape(qToStringViewIgnoringNull(str));
145 static QString wildcardToRegularExpression(
const QString &str, WildcardConversionOptions options = DefaultWildcardConversion)
147 return wildcardToRegularExpression(qToStringViewIgnoringNull(str), options);
150 static inline QString anchoredPattern(
const QString &expression)
152 return anchoredPattern(qToStringViewIgnoringNull(expression));
155 static QString escape(QStringView str);
156 static QString wildcardToRegularExpression(QStringView str, WildcardConversionOptions options = DefaultWildcardConversion);
157 static QString anchoredPattern(QStringView expression);
159 static QRegularExpression fromWildcard(QStringView pattern, Qt::CaseSensitivity cs = Qt::CaseInsensitive,
160 WildcardConversionOptions options = DefaultWildcardConversion);
161#if QT_CORE_REMOVED_SINCE(6
, 8
)
162 bool operator==(
const QRegularExpression &re)
const;
163 inline bool operator!=(
const QRegularExpression &re)
const {
return !operator==(re); }
166 friend Q_CORE_EXPORT
bool comparesEqual(
const QRegularExpression &lhs,
167 const QRegularExpression &rhs)
noexcept;
168 Q_DECLARE_EQUALITY_COMPARABLE(QRegularExpression)
170 friend struct QRegularExpressionPrivate;
171 friend class QRegularExpressionMatch;
172 friend struct QRegularExpressionMatchPrivate;
173 friend class QRegularExpressionMatchIterator;
174 friend Q_CORE_EXPORT size_t qHash(
const QRegularExpression &key, size_t seed)
noexcept;
176 QRegularExpression(QRegularExpressionPrivate &dd);
177 QExplicitlySharedDataPointer<QRegularExpressionPrivate> d;
181Q_DECLARE_OPERATORS_FOR_FLAGS(QRegularExpression::PatternOptions)
182Q_DECLARE_OPERATORS_FOR_FLAGS(QRegularExpression::MatchOptions)
183Q_DECLARE_OPERATORS_FOR_FLAGS(QRegularExpression::WildcardConversionOptions)
185#ifndef QT_NO_DATASTREAM
186Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out,
const QRegularExpression &re);
187Q_CORE_EXPORT
QDataStream &operator>>(QDataStream &in, QRegularExpression &re);
190#ifndef QT_NO_DEBUG_STREAM
191Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QRegularExpression &re);
192Q_CORE_EXPORT
QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOptions);
201 QRegularExpressionMatch();
202 ~QRegularExpressionMatch();
203 QRegularExpressionMatch(
const QRegularExpressionMatch &match);
204 QRegularExpressionMatch(QRegularExpressionMatch &&match) =
default;
205 QRegularExpressionMatch &operator=(
const QRegularExpressionMatch &match);
206 QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match)
noexcept
207 { d.swap(match.d);
return *
this; }
208 void swap(QRegularExpressionMatch &other)
noexcept { d.swap(other.d); }
210 QRegularExpression regularExpression()
const;
211 QRegularExpression::MatchType matchType()
const;
212 QRegularExpression::MatchOptions matchOptions()
const;
214 bool hasMatch()
const;
215 bool hasPartialMatch()
const;
217 bool isValid()
const;
219 int lastCapturedIndex()
const;
221#if QT_CORE_REMOVED_SINCE(6
, 8
)
222 bool hasCaptured(
const QString &name)
const
223 {
return hasCaptured(qToAnyStringViewIgnoringNull(name)); }
224 bool hasCaptured(QStringView name)
const;
226 bool hasCaptured(QAnyStringView name)
const;
227 bool hasCaptured(
int nth)
const;
229 QString captured(
int nth = 0)
const;
230 QStringView capturedView(
int nth = 0)
const;
232#if QT_CORE_REMOVED_SINCE(6
, 8
)
233 QString captured(
const QString &name)
const
234 {
return captured(qToAnyStringViewIgnoringNull(name)); }
236 QString captured(QStringView name)
const;
237 QStringView capturedView(QStringView name)
const;
239 QString captured(QAnyStringView name)
const;
240 QStringView capturedView(QAnyStringView name)
const;
242 QStringList capturedTexts()
const;
244 qsizetype capturedStart(
int nth = 0)
const;
245 qsizetype capturedLength(
int nth = 0)
const;
246 qsizetype capturedEnd(
int nth = 0)
const;
248#if QT_CORE_REMOVED_SINCE(6
, 8
)
249 qsizetype capturedStart(
const QString &name)
const
250 {
return capturedStart(qToAnyStringViewIgnoringNull(name)); }
251 qsizetype capturedLength(
const QString &name)
const
252 {
return capturedLength(qToAnyStringViewIgnoringNull(name)); }
253 qsizetype capturedEnd(
const QString &name)
const
254 {
return capturedEnd(qToAnyStringViewIgnoringNull(name)); }
256 qsizetype capturedStart(QStringView name)
const;
257 qsizetype capturedLength(QStringView name)
const;
258 qsizetype capturedEnd(QStringView name)
const;
260 qsizetype capturedStart(QAnyStringView name)
const;
261 qsizetype capturedLength(QAnyStringView name)
const;
262 qsizetype capturedEnd(QAnyStringView name)
const;
265 friend class QRegularExpression;
266 friend struct QRegularExpressionMatchPrivate;
267 friend class QRegularExpressionMatchIterator;
269 QRegularExpressionMatch(QRegularExpressionMatchPrivate &dd);
270 QExplicitlySharedDataPointer<QRegularExpressionMatchPrivate> d;
275#ifndef QT_NO_DEBUG_STREAM
276Q_CORE_EXPORT
QDebug operator<<(QDebug debug,
const QRegularExpressionMatch &match);
290 QRegularExpressionMatchIterator();
291 ~QRegularExpressionMatchIterator();
292 QRegularExpressionMatchIterator(
const QRegularExpressionMatchIterator &iterator);
293 QRegularExpressionMatchIterator(QRegularExpressionMatchIterator &&iterator) =
default;
294 QRegularExpressionMatchIterator &operator=(
const QRegularExpressionMatchIterator &iterator);
295 QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator)
noexcept
296 { d.swap(iterator.d);
return *
this; }
297 void swap(QRegularExpressionMatchIterator &other)
noexcept { d.swap(other.d); }
299 bool isValid()
const;
301 bool hasNext()
const;
302 QRegularExpressionMatch next();
303 QRegularExpressionMatch peekNext()
const;
305 QRegularExpression regularExpression()
const;
306 QRegularExpression::MatchType matchType()
const;
307 QRegularExpression::MatchOptions matchOptions()
const;
310 friend class QRegularExpression;
311 friend Q_CORE_EXPORT QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(
const QRegularExpressionMatchIterator &iterator);
312 friend QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIteratorSentinel end(
const QRegularExpressionMatchIterator &) {
return {}; }
314 QRegularExpressionMatchIterator(QRegularExpressionMatchIteratorPrivate &dd);
315 QExplicitlySharedDataPointer<QRegularExpressionMatchIteratorPrivate> d;
345 Q_ASSERT_X(!m_atEnd, Q_FUNC_INFO,
"operator* called on an iterator already at the end");
346 return m_currentMatch;
351 Q_ASSERT_X(!m_atEnd, Q_FUNC_INFO,
"operator++ called on an iterator already at the end");
352 if (m_matchIterator.hasNext()) {
353 m_currentMatch = m_matchIterator.next();
355 m_currentMatch = QRegularExpressionMatch();
377 return (&lhs == &rhs);
393 QRegularExpressionMatch m_currentMatch;
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match)
Writes the match object match into the debug object debug for debugging purposes.
\inmodule QtCore \reentrant
QDataStream & operator<<(QDataStream &out, const QRegularExpression &re)
Writes the regular expression re to stream out.
QDataStream & operator>>(QDataStream &in, QRegularExpression &re)
Reads a regular expression from stream in into re.
QDebug operator<<(QDebug debug, const QRegularExpression &re)
Writes the regular expression re into the debug object debug for debugging purposes.
friend bool comparesEqual(const QRegularExpressionMatchIteratorRangeBasedForIterator &lhs, const QRegularExpressionMatchIteratorRangeBasedForIterator &rhs) noexcept
const QRegularExpressionMatch & operator*() const
QRegularExpressionMatchIteratorRangeBasedForIterator operator++(int)
const QRegularExpressionMatch * pointer_type
QRegularExpressionMatchIteratorRangeBasedForIterator(const QRegularExpressionMatchIterator &iterator)
const QRegularExpressionMatch & reference_type
std::forward_iterator_tag iterator_category
QRegularExpressionMatchIteratorRangeBasedForIterator & operator++()
QRegularExpressionMatch value_type
QRegularExpressionMatchIteratorRangeBasedForIterator()
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)
static pcre2_jit_stack_16 * qtPcreCallback(void *)
static int convertToPcreOptions(QRegularExpression::PatternOptions patternOptions)
bool comparesEqual(const QRegularExpression &lhs, const QRegularExpression &rhs) noexcept
Q_DECL_COLD_FUNCTION void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *cls, const char *method)
static bool isJitEnabled()
static int safe_pcre2_match_16(const pcre2_code_16 *code, PCRE2_SPTR16 subject, qsizetype length, qsizetype startOffset, int options, pcre2_match_data_16 *matchData, pcre2_match_context_16 *matchContext)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QT_REQUIRE_CONFIG(regularexpression)
QRegularExpressionMatch next
QRegularExpressionMatchIteratorPrivate(const QRegularExpression &re, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions, const QRegularExpressionMatch &next)
const QRegularExpression regularExpression
const QRegularExpression::MatchOptions matchOptions
const QRegularExpression::MatchType matchType
QRegularExpressionMatchPrivate(const QRegularExpression &re, const QString &subjectStorage, QStringView subject, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions)
const QRegularExpression::MatchType matchType
const QRegularExpression::MatchOptions matchOptions
const QString subjectStorage
QList< qsizetype > capturedOffsets
QRegularExpressionMatch nextMatch() const
const QRegularExpression regularExpression
const QStringView subject
QRegularExpressionPrivate(const QRegularExpressionPrivate &other)
int captureIndexForName(QAnyStringView name) const
pcre2_code_16 * compiledPattern
void doMatch(QRegularExpressionMatchPrivate *priv, qsizetype offset, CheckSubjectStringOption checkSubjectStringOption=CheckSubjectString, const QRegularExpressionMatchPrivate *previous=nullptr) const
void cleanCompiledPattern()
QRegularExpressionPrivate()
~QRegularExpressionPrivate()
QRegularExpression::PatternOptions patternOptions