views:

26

answers:

3
/** Constant <code>IDX_USER="IDX_+ USER_ID"</code> */

I have several lines of code which was generated by javadoc and show up something like the above. I would want to find all lines starting with /** Constant IDX_ and all the way to the end of the line.

How should I do this? Will be using the regex search and replace capability in Eclipse to manipulate the modifications

+1  A: 

You can use the special character ^ to indicate that your regular expression starts at the beginning of a line. For example, given your regex, you could search for:

^\/\*\* Constant IDX_

You probably also want to allow whitespace prior to the comment. The regular expression [ \t]* will match zero or more spaces or tabs, making the following regular expression:

^[\t ]*\/\*\* Constant IDX_

match anything starting with /** Constant IDX_ (allowing whitespace at the beginning of the line).

If you want the entire line (perhaps to capture the contents of the comment after your regex, you can use $ to indicate the end of a line, and . to match any character. Combine this with * (to indicate zero or more occurences), and you'll end up with:

^[\t ]*\/\*\* Constant IDX_.*$
Ryan Brunner
my starting text should be /** Constant IDX_, I am not sure how to mention everything else till the end for strings which start with the above text
Joshua
In that case, you can just include Constant IDX_ within your regular expression. I've updated my answer.
Ryan Brunner
thanks this definitely helps, but I would like to replace this line with nothing. Currently it replaces with an empty line, how should I fix this?
Joshua
then you need to add something like [\r\n]* in the end to also match following line break(s). just added it to my answer
zolex
A: 

I would use this one.

^\/\*\* Constant IDX_.*$

A good place to test your expression is http://gskinner.com/RegExr/ Try out your own. But the above regexpr is working great.

BitKFu
A: 
\s*\/\*{2}\s*Constant\s*(?:<code>)?(IDX_.*)="(.+)"(?:<\/code>)?\s*\*\/[\r\n]*

will store the constant's name in $1 and it's value in $2 according to your given example. <code>-tags are optional, white spaces don't matter

zolex