-1

I could have few valid strings in my application. Such valid strings may include:

 "attached:yes blocked:yes"        #No ()
 "attached:yes blocked:(yes)"      #Blocked has ()
 "attached:(yes) blocked:yes"      #Attached has ()
 "attached:(yes) blocked:(yes)"    #Both have ()

If I find blocked:(yes) or blocked:yes in any of the above strings, I would like to have the indices of the start and end of the matched part. So basically ignore ( or )

EXAMPLES

attached:yes blocked:yes should give two indices start and end of substring of blocked:yes, which is (13, 24)

attached:yes blocked:(yes) should give two indices start and end of substring of blocked:(yes), which is (13, 26)

armitus
  • 712
  • 5
  • 20
Vallabh Patade
  • 4,960
  • 6
  • 31
  • 40

1 Answers1

0

1st. Find out what library can you use to utilize regular expressions.

2nd. Below is an example of the regular expression.|

What I am saying in the regular expression is to obtain group 1 and group 2 where the values can be 'yes' or '(yes)'

attached:([(]?yes[)]?) blocked:([(]?yes[)]?)

enter image description here The more sure you will be using the regex library:

#include <regex>
using namespace std;

Here are some links that talk about regular expressions in C++:

Let me know if this is pointing you to the right direction, else I can remove this answer.

acarlstein
  • 1,799
  • 2
  • 13
  • 21