Tuesday 15 May 2012

regex - white space in Regular expression -


I am using this software, DK-BRICS-Automation, to get the number of regular expressions. Now, for example, I have this kind of RE:

  ^ SEARCH \ s + [^ \ n] {10}   

When I Below is a string, the compiler says that invalid escape sequence

  RegExp r = new RegExp ("^ SEARCH \ s + [^ \ n] {10}", ALL);   

Where all is a fixed flag

When I use double back slashes before a small, the compiler accepts it as a string But here it means space but I am confused when I use double back slash, then it will just consider the back slash and "S", where I want white space.

Now, I have thousands such regular expressions for which I want to calculate the finite automaton states. So, does this mean that I have to add a slash manually to all RE?

Here is a link where he has explained something related to this but I am not getting this:

/ P> Please help me if someone has any previous experience in this software or if you have any idea to solve this problem.

I got another look at that document. "Automation" is a Java package, so I think you have to behave like Java Reggues. So just double backslash each backslash into a regedx.

Here it is, Java does not know the "raw" strings, then you have to save for the two levels. The first level that evaluates the escape sequence is the string level.

The string escape sequence \ s does not know, this error is \ n OK, the string evaluates it and instead the two letters \ (0x5C) and n (0x6E) character 0x0A .

The string is then stored and handed over to the regex constructor. Here is the next round of escape sequence evaluation.

So if you want to avoid the regex level, then you have to double backslash. The string level will evaluate \\ to \ and therefore the regex level receives the correct escape chain.

No comments:

Post a Comment