thetna
thetna

Reputation: 7143

performing regular expression in C

I would like to perform regular expression in C . Suppose I have following text like:

  thecapital([x], implies(maincity(y),x))

The program has to output like:

   implies(maincity(y),x))

can anyone please suggest how shall I proceed?

Upvotes: 0

Views: 459

Answers (1)

Roland Illig
Roland Illig

Reputation: 41627

To transform the input string thecapital([x], implies(maincity(y),x)) to the output string implies(maincity(y),x)) you can use the following simple function:

const char *
transform(const char *expr) {
  return expr + 16;
}

It doesn't use regular expressions, but on the other hand it's lightning fast. Or maybe you didn't put your question clearly. For example, you didn't describe in words what transformation should be done. Giving just one example is not enough.

So what do you really want to do:?

  • Skip the first 16 characters of the input string
  • Return everything after the first space character
  • Return everything after the last space character
  • Return the suffix of the argument starting with the second i
  • Return "implies(maincity(y),x))"
  • Return the second argument to the term in parentheses, followed by an extra closing parenthesis

For your one example my simple suggested function fulfills all these requirements. But of course it will fail hopelessly when given any other input.

Upvotes: 4

Related Questions