473,382 Members | 1,665 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,382 software developers and data experts.

Using Regular Expression in java

19
Hi All,

I have a string in which I have to find all the commas except the one which is followed by "space". I have tried ",[^ ], but it finds the patterns that start with , and one character.
e.g If my string is abc,bef, ghi,jkl,,mno
the it returns ',b' ',j' and ',,' while I want only ',' so that it can search from the next element in the string. Means it should return ',' ',' ','.

Thanks
Gaurav
Sep 4 '09 #1
5 2103
r035198x
13,262 8TB
Try the negative look behind pattern "(?<! ),";
Sep 4 '09 #2
gjain12
19
Actually I am very novice to regular expression.
If you can provide me some exampl sort of for the same, it will be really helpful.
Sep 4 '09 #3
r035198x
13,262 8TB
Now that I've read your post again I realize that you said followed by a space not preceded by a space.
You need the negative look ahead instead.
Expand|Select|Wrap|Line Numbers
  1.                 String p = ",(?! )";
  2.         String input = "abc,bef, ghi,jkl, ,mno";
  3.         Pattern pattern = Pattern.compile(p);
  4.         Matcher matcher = pattern.matcher(input);
  5.         boolean found = false;
  6.         while (matcher.find()) {
  7.             System.out.format("I found the text \"%s\" starting at " + "index %d and ending at index %d.%n", matcher.group(), matcher.start(), matcher.end());
  8.             found = true;
  9.         }
  10.         if (!found) {
  11.             System.out.format("No match found.%n");
  12.         }
  13.  
Sep 4 '09 #4
gjain12
19
Thanks a lot..
It works perfectly...
But I couldn't iunderstand how this regex is working.
Means how should I read this expression.
If you can explain it also it will be a great leraning experience.
Sep 4 '09 #5
r035198x
13,262 8TB
See the entries for those things in the regex tutorial.
Sep 4 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ye Zhou | last post by:
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...
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...
11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
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...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
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...
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...
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...
6
by: pro | last post by:
Hi everyone, I would like to ask something about regular expressions in java. I have made a code lika that cleanString = cleanString.replaceAll(";", " ; "); cleanString =...
14
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.