Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6141739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:17:29+00:00 2026-05-23T18:17:29+00:00

How do I process following PHP regex in Java: if(preg_match(/\r\n(.*?)\$/,$req,$match)){ $data=$match[1]; } This line

  • 0

How do I process following PHP regex in Java:

if(preg_match("/\r\n(.*?)\$/",$req,$match)){ $data=$match[1]; }

This line is part of following function, by the way:

function getheaders($req){
  $r=$h=$o=null;
  if(preg_match("/GET (.*) HTTP/"   ,$req,$match)){ $r=$match[1]; }
  if(preg_match("/Host: (.*)\r\n/"  ,$req,$match)){ $h=$match[1]; }
  if(preg_match("/Origin: (.*)\r\n/",$req,$match)){ $o=$match[1]; }
  if(preg_match("/Sec-WebSocket-Key2: (.*)\r\n/",$req,$match)){ $key2=$match[1]; }
  if(preg_match("/Sec-WebSocket-Key1: (.*)\r\n/",$req,$match)){ $key1=$match[1]; }
  if(preg_match("/\r\n(.*?)\$/",$req,$match)){ $data=$match[1]; }
  return array($r,$h,$o,$key1,$key2,$data);
}

Thanks in advance!

So far I have:

Matcher matcher = Pattern.compile("\r\n(.*?)\\$").matcher(req);
while(matcher.find()){
    data = matcher.group(1);
}

I am sure, however, that this is wrong.

Ok guys, thanks for your answers, but they did not help yet. May I ask you to tell me, however, what this regex means:

  if(preg_match("/\r\n(.*?)\$/",$req,$match)){ $data=$match[1]; }

I know, that if it does find a match with /\r\n(.*?)\$/ in the string $req, it will save the different kinds of mathces into the array $match. BUT: what is being matched here? And what’s the difference between $match[0] and $match[1]? Maybe, if I understand this, I will be able to reconstruct the way to produce equal results in Java.

Thanks Jaroslav, but:

The string I am trying to process however (the last line of the handshake sent to me by Google Chrome, is:

Cookie: 34ad04df964553fb6017b93d35dccd5f=%7C34%7C36%7C37%7C40%7C41%7C42%7C43%7C44%7C45%7C46%7C47%7C48%7C49%7C50%7C52%7C53%7C54%7C55%7C56%7C57%7C58%7C59%7C60%7C61%7C62%7C63%7C64%7C65%7C66%7C67%7C68%7C69%7C70%7C71%7C72%7C73%7C74%7C75%7C76%7C77%7C78%7C79%7C80%7C81%7C82%7C83%7C84%7C85%7C86%7C87%7C88%7C89%7C90%7C91%7C92%7C93%7C94%7C95%7C96%7C97%7C98%7C99%7C100%7C101%7C102%7C103%7C104%7C105%7C106%7C107%7C108%7C109%7C110%7C111%7C112%7C113%7C114%7C115%7C116%7C117%7C118%7C119%7C120%7C121%7C122%7C123%7C124%7C125%7C126%7C127%7C128%7C129%7C130%7C131%7C132%7C133%7C134%7C135%7C136%7C137%7C138%7C139%7C%3B%7C%3B%7C%3B%7C%3B1%3B2%3B3%3B4%3B5%3B6%3B7%3B8%3B9%3B10%3B11%3B14%3B15%3B18%3B23%3B24%3B25%3B26%3B28%3B29%3B30%3B31%3B32%3B33%3B%7C

Hey guys, I just now realize what I have been asking was irrelevant 🙁 But one answer has been right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:17:30+00:00Added an answer on May 23, 2026 at 6:17 pm
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    
    public class SplitDemo2 {
    
        private static final String REGEX = "/\\r\\n(.*?)\\$/";
        private static final String INPUT = "/GET (.*) HTTP/";
    
        public static void main(String[] args) {
            Pattern p = Pattern.compile(REGEX);
            Matcher m = p.matcher(INPUT); // get a matcher object
            int count = 0;
    
            while(m.find()) {
              count++;
              System.out.println("Match number "+count);
              System.out.println("start(): "+m.start());
              System.out.println("end(): "+m.end());
       }
    }
    

    }

    More info on regex http://download.oracle.com/javase/tutorial/essential/regex/matcher.html

    Explanation of your regex

    \r\n(.*?)\$
    

    \r Carriage return character.

    \n Line break character.

    (.*?) A numbered capture group

    \$ Matches a $ character.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I launch the following command line (process) from a Windows VC++ 6 program using
I was surprised when I just tried the following PHP code: function foo() {
Consider the following example: <form action=process.php id=myForm> ..... ....... all my form elements </form>
I am doing the following in PHP: exec('java -jar /opt/flex3/lib/mxmlc.jar +flexlib /opt/flex3/frameworks MyAS3App.as -default-size
i have following php code which display company logo <?php $key=$_GET['key']; /// key process
I configured my NGINX for Zend in the following way (PHP 5.3 with fpm):
I am currently trying to process a csv file in PHP using preg_match(). An
I have the following setup: An endless running PHP process that looks at a
I have encountered the following query as part of a PHP application. The query
I'm teaching/helping a student to program. I remember the following process always helped me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.