Find a complex substring in another string
-
Hi everybody,
I have a substring for example:
43ab??12??56??ef
?? are wildcard and the count of ?? is unknown.
I want to check the main string contains this substring or not.
The substring is not unique and it changes always. -
Hi,
You want to use Regular Expressions. Use this as your pattern:
43ab.*12.*56.*ef
-
@MohammadReza said:
@JKSH Hi dear JKSH. Thanks for your reply.
I know but my substring is unpredictable and I can not use a constant regular expression.Well, what are the characteristics that are common to all of your substrings? You need to identify this information first, before you can design your search logic.
How are these substrings generated? What are they used for? What other things do your "main string" contain?
-
@JKSH Thanks.
By using of RegExp, the problem is solved.
For other users who read this question:
My main string is a string of hex (without any space or \x or 0x). I replcae?
in substring by[0-9a-f]
and useQt::CaseInsensitive
option:regex.replace("?","[0-9a-f]"); index = mainString.indexOf(QRegExp(regex,Qt::CaseInsensitive));