How to search a line starting with a certain text using regex
/** 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? Wil开发者_C百科l be using the regex search and replace capability in Eclipse to manipulate the modifications
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_.*$
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.
\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
精彩评论