473,464 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regularexpression not working.

dmjpro
2,476 Top Contributor
Expand|Select|Wrap|Line Numbers
  1. String text = "/** */test/** */test";
  2. System.out.println(text.replaceAll("/\\*\\*.*\\*/"));
  3.  
It prints test instead of testtest. How regular expression is working here?
Apr 28 '10 #1

✓ answered by dmjpro

Yea .. i solved the problem.

Expand|Select|Wrap|Line Numbers
  1. while((line = br.readLine()) != null){
  2.             js_text.append(line.trim().replaceAll("//.*", "")); //gets the file text(removed comments //)
  3.         }
  4.  
Expand|Select|Wrap|Line Numbers
  1. int start=0,end=0 ;
  2.         while((start = js_text.indexOf("/*")) != -1){
  3.             end = js_text.indexOf("*/");
  4.             if(end != -1){
  5.                 js_text.replace(start, end+2, "");
  6.             }
  7.         }
  8.  
Thanks a lot ...

4 1435
jkmyoung
2,057 Recognized Expert Top Contributor
It looks like the largest possible substring is being returned in the match, so the substring " */test/** " is matched by .*
Apr 28 '10 #2
dmjpro
2,476 Top Contributor
Then how should I remove /** */? Actually i m trying to remove the documentation part from my JS file when i expose this on web.
Apr 29 '10 #3
pbrockway2
151 Recognized Expert New Member
There's a good description of regular expressions at http://www.regular-expressions.info/. (The * is being greedy.)

Alteratively, since slash-star comments don't nest you could just use String's indexOf().
Apr 29 '10 #4
dmjpro
2,476 Top Contributor
Yea .. i solved the problem.

Expand|Select|Wrap|Line Numbers
  1. while((line = br.readLine()) != null){
  2.             js_text.append(line.trim().replaceAll("//.*", "")); //gets the file text(removed comments //)
  3.         }
  4.  
Expand|Select|Wrap|Line Numbers
  1. int start=0,end=0 ;
  2.         while((start = js_text.indexOf("/*")) != -1){
  3.             end = js_text.indexOf("*/");
  4.             if(end != -1){
  5.                 js_text.replace(start, end+2, "");
  6.             }
  7.         }
  8.  
Thanks a lot ...
Apr 30 '10 #5

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

Similar topics

1
by: mg | last post by:
Does someone have RegularExpression code (C# WebForm) for server-side validation of Date (mm/dd/yyyy) ... including leap year?
2
by: John Hoge | last post by:
I have a regex "^\d{5}$" that does not allow blanks, but the RegularExpressionValidator does not fire for empty fields. Is there a way to make it do so? I would rather not include a separate...
1
by: fabrice | last post by:
Hello, In a search form, i want to permit few characters (see below) and some signs as - _ / , . So thios my RegularExpression and it works. ValidationExpression="{4,20}" But i'd would...
1
by: Nicola Farina | last post by:
Hi all, i've a form with a textbox that user "must" fill with a password. I want to check if there's a password inside, and if it's between 6 an 8 chars. I've placed a regularexpression...
2
by: Fabio | last post by:
Hi all, I have this simple string for example: anything<font>catch this</font> and I need a regularexpression to Catch "catch this" so, I can use this pattern: ">+"
2
by: den 2005 | last post by:
Hi everybody, How do restrict entering these characters <>\"%';()& and telling user these caharcters are not allowed to be enter in the textbox field using RegularExpression Validator? I put in...
3
by: Arpan | last post by:
Consider the following code which validates a TextBox using RegularExpression: <form id="form1" runat="server"> <asp:TextBox id="txt1" runat="server"/> <asp:RegularExpressionValidator...
1
by: Arpan | last post by:
Using RegularExpression, I want to validate a TextBox so that the TextBox accepts only 8-digit numbers. This can be done with the following RegularExpression: {8} But how do I validate the...
1
by: prp | last post by:
hi all, I have a problem.Suppose I use a regularexpression validator for zip code. An User fill wrong entry in the relevant textbox then regularexpression validator fires.but user did not...
0
by: softimasrinivas | last post by:
Regular Expression: ((\d{1,2},)?(\d{3},)*(\d{1,3}))|(\d+) I have a textbox that should allow 123,123,123,123,123,1 format.TextBox MaxLength is 21.The Problem is it should accept when you give...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.