![]() ![]() in the pattern matches any character including a newline. At the demo Web site, single backslashes must be used, I am doubling them here for the QRegExp.Note the use of non-capturing groups, it does not store any captured texts and potentially improves performance as compared to capturing groups that save the matched text in a buffer. To add more alternatives, we can use an alternation operator |, and we can do it like this: ^(?!.*\\b(?:words|to|exclude)\\b).*\\b(?:words|to|include)\\b. Now, it does not match the string in question. To prevent the match in case the string contains the word ipsum, you need to use the lookahead at the very beginning of the string. The regex is \\blorem\\b (with QRegExp.CaseInsensitive set to 1) where \b is used to force whole word matching. You say, you have Lorem ipsum dolor sit amet, consectetur adipiscing elit., and you want it to match since it contains the word lorem. Use excluded words as alternatives inside an anchored negative look-ahead. I think there is no need in a tempered greedy quantifier. I considered doing a regex to filter out the articles with the words that I want and then run a second regex excluding articles from the first set that I do not want, but unfortunately the software I am using does not allow me to do this. But if ipsum is a word that I'm excluding, I do not want article A to be filtered. Then a regex that includes lorem would filter article A but not B. ![]() So for example if article A is: Lorem ipsum dolor sit amet, consectetur adipiscing elit.Īnd article B is: Vivamus fermentum semper porta. So I tried this (which returned nothing): ^(words|I|want|to|include)(?:(?!the|ones|that|should|not|match).)*$Įdit: The reason why I need such an unusual regex (include/exclude) is because I want to search through a series of articles and filter the ones that have the included words in them but not if they also have the excluded words in them. Here are some of the things I tried (this example included all of the words): (words|I|want|to|include)(?!the|ones|that|should|not|match) I am trying to exclude a group of words but include another group of words in a qregexp expression but I am currently having issues figuring this out. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |