Regular expression for string in c

I am working on writing a regular expression used to test a string in C. That's what I'm still up to

'^"[A-Za-z0-9]*[\t\n]*"$'

for rules - A line must begin with double quotes - Cannot contain a newline character

However, I cannot fix a rule allowing "\" or "" in a string if it is preceded by "\". Here is what I tried:

'^"[A-Za-z0-9]*[\t\n]*[\\\|\\"]?"$'

But this does not seem to work. What could be wrong with regex here?

Regards, darkie15

+3
source share
2 answers

If you want this regex:

^"[A-Za-z0-9]*[\t\n]*"$

To mark in C, you must have double quotes around the string. Then you should avoid screens and double quotes inside the expression.

:

"^\"[A-Za-z0-9]*[\\t\\n]*\"$"
0

; [\\\|\\"] - , .

- :

^"([A-Za-z0-9\t]|\\\\|\\")*"$

+2

Source: https://habr.com/ru/post/1747724/


All Articles