Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 169 Vote(s) - 3.64 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lex/Flex :Regular expression for string literals in C/C++?

#1
I look here [ANSI C grammar][1] .


[1]:

[To see links please register here]


This page includes a lot of regular expressions in Lex/Flex for ANSI C.

Having a problem in understanding regular expression for string literals.

They have mentioned regular expression as `\"(\\.|[^\\"])*\"`

As I can understand `\"` this is used for double quotes, `\\` is for escape character, `.` is for any character except `escape character` and `*` is for zero or more times.

`[^\\"]` implies characters except `\` , `"` .

So, in my opinion, regular expression should be `\"(\\.)*\"`.

Can you give some strings where above regular expression will fail?

or

Why they have used `[^\\"]`?
Reply

#2
The regex `\"(\\.)*\"` that you proposed matches strings that consist of `\` symbols alternating with any characters like:

"\z\x\p\r"

This regular expression would therefore fail to match a string like:

"hello"

The string `"hello"` would be matched by the regex `\".*\"` but that would also match the string `""""` or `"\"` both of which are invalid.

To get rid of these invalid matches we can use `\"[^\\"]*\"`, but this will now fail to match a string like `"\a\a\a"` which is a valid string.

As we saw `\"(\\.)*\"` does match this string, so all we need to do is combine these two to get `\"(\\.|[^\\"])*\"`.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through