Jump to content

Unable to "decrypt" a regular expression.


RA_SH

Recommended Posts

Hi,

    There is a regular expression which i am not able to figure out.

I am supposed to format a CLOB data for which i have the php code. I have come across this regular expression and preg_split function.

I am just not able to understand what this does. Any help is greatly appreciated.

 

preg_split('/\n1[^\n]*\n-/', $str);

.

 

After i find out what s happening here, i have to figure out a way to translate this to java.

 

Thanks!!!!

Link to comment
https://forums.phpfreaks.com/topic/261581-unable-to-decrypt-a-regular-expression/
Share on other sites

This regular expression will split a string wherever it finds the following consecutive match:

 

1. A newline

2. The number '1'

3. All characters until the newline on this row

4. A newline

5. A hypen (-) or minus character

 

So it would match the red in the following string:

 

0+432jkrouwer{€$@£$@^??423

1doeriwep4892304234puopi42348034

-iodfugo89042432purewrwerpuwer

<< Moving to the Reg Ex forum >>

 

I'd make one clarification to silkfire's explanation. The #3 condition is logically an optional condition since it matches 0 or more characters. In other words, there do not need to be any characters between the number "1" (item #2) and the subsequent newline for item #4. So, the regular expression would also match the following in red:

 

0+432jkrouwer{€$@£$@^??423

1

-iodfugo89042432purewrwerpuwer

 

Also, to simply state the expression in English, it matches any line that line that starts with a 1 followed by a line that starts with a dash.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.