473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

regular expression in Java

Hi all,

I am trying to convert a perl program into java and I got stuck in the
regular expression part. It seems like java.util.regex couldn't help
much. I checked with Apache regexp and didn't get the right way to do
it either. Therefore, I am writing to see if someone could throw a
light on how to do a translation on the statement below.

if ($xml =~ m/^.*?<Transaction.*?instanceId="(.*?)".*?receiver=" (.*?)".*?sender="(.*?)".*?transactionId="(.*?)".*?/s)
{
return ($1, $4, $3, $2);

Your help is greatly appreciated.

Thanks,
Ye
Jul 17 '05 #1
1 2427
ye****@vt.edu (Ye Zhou) wrote in
news:c4**************************@posting.google.c om:
Hi all,

I am trying to convert a perl program into java and I got stuck in the
regular expression part. It seems like java.util.regex couldn't help
much. I checked with Apache regexp and didn't get the right way to do
it either. Therefore, I am writing to see if someone could throw a
light on how to do a translation on the statement below.

if ($xml =~
m/^.*?<Transaction.*?instanceId="(.*?)".*?receiver=" (.*?)".*? sender="(. *?)".*?transactionId="(.*?)".*?/s) {
return ($1, $4, $3, $2);

Your help is greatly appreciated.

Thanks,
Ye

Try this...

String regex = ".*?<Transaction.*?instanceId="(.*?)".*?receiver=" (.*?)".
*?sender="(.> *?)".*?transactionId="(.*?)".*?";

Pattern p = Pattern.compile(regex);
Matcher m = pattern.match(xml);
if (m.matches())
return new String[] {m.group(1), m.group(4), m.group(3), m.group(2)};
Cheers,
Alex
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jack Smith | last post by:
I posted this question earlier, but I got no responses. Can anyone help me out here...any hints or even how to start? Thanks in advance. Let doubleswap(x) be the string formed by replacing each...
10
by: Harlin Seritt | last post by:
I have been looking at the Python re module and have been trying to make sense of a simple function that I'd like to do. However, no amount of reading or googling has helped me with this. Forgive...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
5
by: Markus Innerebner | last post by:
Hello to everyone, Yesterday I tried long time to make a validation for a number format input field. As I am using Regex in Java I wrote following expression: String pattern =...
1
by: passion_to_be_free | last post by:
I am writing a javascript that will make an http request, sort through the html for any links on the page, and then store them for future processing. To test things, I pasted html source code...
19
by: Davy | last post by:
Hi all, I am a C/C++/Perl user and want to switch to Python (I found Python is more similar to C). Does Python support robust regular expression like Perl? And Python and Perl's File...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
6
by: rorymo | last post by:
I have a regular expression that allows only certain characters to be valid in an xml doc as follows: <xs:pattern value="^*" /> What I want to do is also allow any unicode character that is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.