How can I use wildcards with string::find?


I want to be able to use a wildcard in string::find and then fetch what was in that wildcard place.

For example:

if (string::npos !=input.find("How is * doing?") { cout<<"(the wildcard) is doing fine."<<endl; }

And so if I ask, "How is Mom doing?", the output would be "Mom is doing fine."

What libraries would I use for this, or how would I write the code manually? If I should use AIML, can AIML execute .bat files?


Regarding your question on how to do it manually, i will give you an idea with this simple code, which solves the example which you gave in the question.

#include<iostream> #include<string> using namespace std; int main() { string expr="How is * doing?"; string input="How is Mom doing?"; int wildcard_pos=expr.find("*"); if(wildcard_pos!=string::npos) { int foo=input.find(expr.substr(0,wildcard_pos)),bar=input.find(expr.substr(wildcard_pos+1)); if(foo!=string::npos && bar!=string::npos) cout<<input.substr(wildcard_pos,bar-wildcard_pos)<<" is doing fine\n"; } }

You can easily modify this idea to suit your needs. Else, follow the answer given by src


C++ 2011 provides a <a href="http://en.wikipedia.org/wiki/C%2B%2B11#Regular_expressions" rel="nofollow">regular expression library</a>. If you can't use C++ 2011 yet you can use the <a href="http://www.boost.org/doc/libs/1_50_0/libs/regex/doc/html/index.html" rel="nofollow">Boost.Regex</a> library or any C library like <a href="http://www.pcre.org/" rel="nofollow">PCRE</a>.


  • Select column value that matches a combination of other columns values on the same table
  • Setting the default active profile in Spring-boot
  • Through VBA use existing database if open, otherwise open new one then close after
  • How to hide content not in vissible view on a page with many HTML elements to improve performance?
  • How to make the page script recognize a manually changed value of INPUT element?
  • How to extract part of the *original* text from JSON with Jackson?
  • How to find all the agents who are not included in an agentset?
  • Forward slash in last argument causes path to directory of batch file (“%~dp0”) to change
  • How to get all use statements declared in PHP class file
  • SvcUtil.exe vs Add Reference
  • SVG Fill Width to Child Elements
  • include dlls in visual studio c++ 2008
  • react split panel resize
  • Can you pass an array from javascript to asp.net mvc controller action without using a form?
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • how does System.Web.HttpRequest::PathInfo work?
  • Security issues with PHP's Readfile method
  • Run multiple queries from 1 SQL file showing result in multiple tables
  • Unable to install Git-core+svn by MacPorts
  • Django simple Captcha “No module named fields” error
  • onBackPressed() not being executed
  • Test if a set exists before trying to drop it
  • Could not find rake using whenever rails
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Read text file and split every line in MSBuild
  • C# - Serializing and deserializing static member
  • How to add date and time under each post in guestbook in google app engine
  • Java applet as stand-alone Windows application?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Delete MySQLi record without showing the id in the URL
  • Error creating VM instance in Google Compute Engine
  • Acquiring multiple attributes from .xml file in c#
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Programmatically clearing map cache
  • java string with new operator and a literal