3

I've a C++11 file using regex that I'm converting to a C++98 file. In the file, I've this line that does some manipulation that I don't understand.

regex separator_regex(R"((([[:alpha:]]:[^:;]*)|([^:;]*))([:;]|$))");.

If I'm correct, seperator_regex is a regex class, and R is used as a raw string literal so the code doesn't exit out. However, what is the rest of the snippet trying to do?

KenB
  • 91
  • 5
  • 2
    The rest of the code is a regular expression. – eerorika Nov 21 '18 at 19:26
  • Yes, my question is what does it mean? What is it trying to do? – KenB Nov 21 '18 at 19:27
  • I don't envy you at all, C++11 has a lot of good stuff that's missing in C++98. And regular expressions are much harder to read than they are to write. – Mark Ransom Nov 21 '18 at 19:27
  • Have you tried reading a regexp tutorial, such as www.regular-expression.info? – Barmar Nov 21 '18 at 19:36
  • You can also paste the regexp into regex101.com. It will show a description of what each piece means. – Barmar Nov 21 '18 at 19:37
  • Regular expressions are a good example of write-only languages. – Pete Becker Nov 21 '18 at 19:43
  • If the linked question doesn't answer your question ((it lists the languages it covers, and C++ isn't one of them - OTOH, this is all pretty basic), @mention me, and I will reopen it. – Martin Bonner supports Monica Nov 21 '18 at 19:44
  • 1
    Your options are: 1. Use Boost Regexp. 2. Rewrite the parser by hand. 3. Rewrite using (eg) flex/bison. 4. Decide that all the previous are too expensive, and (biting the bullet) upgrade to C++11. – Martin Bonner supports Monica Nov 21 '18 at 19:46
  • @MartinBonner I still couldn't figure it out, I'd a look over the internet, although I guess I`m fairly new to programming. – KenB Nov 21 '18 at 19:46
  • @MartinBonner unfortunately, I'm going to have to go with the second option and rewrite this by hand, which is why I wanted to understand it first. – KenB Nov 21 '18 at 19:47
  • So why doesn't the linked duplicate cover your question? – Martin Bonner supports Monica Nov 21 '18 at 19:50
  • I honestly still don't understand the answer to my question – KenB Nov 21 '18 at 20:00
  • 1
    I can't answer since it's been marked as duplicate unfortunately. Did something like regex101.com not solve explain it well enough? – CoffeeTableEspresso Nov 21 '18 at 20:44
  • It is a dupe of "What does this regex mean" because all you need to understand a simple regex like this is there. There are tons of links to online regex debuggers. See [your pattern explanation and demo](https://regex101.com/r/szSyRA/1). It the same as [this one without capturing groups](https://regex101.com/r/szSyRA/3). – Wiktor Stribiżew Nov 21 '18 at 21:44

0 Answers0