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
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

Link to comment
Share on other sites

<< 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.