-2

Could anybody explain me how a regex should look like if I want to match from:

section(test) only the string test?

Condition is that the string section has to be in front of (test)

Thanks for any help

CrustyCheese
  • 49
  • 1
  • 5

1 Answers1

2

For the regex:

section\((.*)\)

Explaination:

  • section : for the string string that need to be there (your condition)
  • \( : escape the ( to match it
  • (.*) : capture everything (the thing you want to match)
  • \) : escape ) and close, which is also the ending condition of the "capture everything"

See the demo

I assumed you want everything between the ( )

EDIT regex101 details :

  • section matches the characters section literally (case sensitive)
  • ( matches the character ( literally
  • Capturing group (.*)
    • .* matches any character (except newline) Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
  • ) matches the character ) literally
Simon PA
  • 748
  • 13
  • 26
  • The tags (if not the text of the question) indicate that OP is looking for a regex which works with the (f)lex scanner generator. (F)lex does not provide captures. Its regexes can certainly use parentheses for grouping but there is no mechanism for retrieving the text matched by a parenthesized subpattern of a regex. – rici Sep 22 '16 at 05:27