RA_SH Posted April 25, 2012 Share Posted April 25, 2012 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!!!! Quote Link to comment https://forums.phpfreaks.com/topic/261581-unable-to-decrypt-a-regular-expression/ Share on other sites More sharing options...
silkfire Posted April 25, 2012 Share Posted April 25, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261581-unable-to-decrypt-a-regular-expression/#findComment-1340395 Share on other sites More sharing options...
Psycho Posted April 25, 2012 Share Posted April 25, 2012 << 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. Quote Link to comment https://forums.phpfreaks.com/topic/261581-unable-to-decrypt-a-regular-expression/#findComment-1340439 Share on other sites More sharing options...
Jessica Posted April 25, 2012 Share Posted April 25, 2012 After i find out what s happening here, i have to figure out a way to translate this to java. Regular expressions are regular expressions regardless of what language you use them in. Quote Link to comment https://forums.phpfreaks.com/topic/261581-unable-to-decrypt-a-regular-expression/#findComment-1340455 Share on other sites More sharing options...
xyph Posted April 25, 2012 Share Posted April 25, 2012 There are different implementations of RegEx. It's more like PCREs are PCREs. Java uses a system with a very, very similar syntax to libpcre, though, so you're pretty safe. Quote Link to comment https://forums.phpfreaks.com/topic/261581-unable-to-decrypt-a-regular-expression/#findComment-1340471 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.