Difference between revisions of "WDSC Find Tips"
(New page: === To find camel case words. === # Open find with Ctrl-F # Key in "([a-z]|[A-Z])[a-z]+[A-Z]+[a-z]+(\W|\b)" into the <u>F</u>ind box (Alt-F) # <u>C</u>hoose case sensitive (Alt-C) # Wh<u>o...) |
Starbuck5250 (talk | contribs) (+link to shortcuts) |
||
(23 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | == | + | {{AN}} - A useful ways to search for text in members/editors |
+ | |||
+ | __FORCETOC__ | ||
+ | |||
+ | |||
+ | == Find camel case words. == | ||
# Open find with Ctrl-F | # Open find with Ctrl-F | ||
− | # Key in "([a-z]|[A-Z])[a-z]+[A-Z]+[a-z]+(\W|\b)" into the <u>F</u>ind box (Alt-F) | + | # Key in "([a-z]|[A-Z])[a-z]+[A-Z]+[a-z]+(\W|\b)" (without the quotes) into the <u>F</u>ind box (Alt-F) |
# <u>C</u>hoose case sensitive (Alt-C) | # <u>C</u>hoose case sensitive (Alt-C) | ||
# Wh<u>o</u>le word (Alt-O) | # Wh<u>o</u>le word (Alt-O) | ||
# Regular e<u>x</u>pression (Alt-X) | # Regular e<u>x</u>pression (Alt-X) | ||
− | The regular expression is | + | :The regular expression is broken down like this |
− | ;([a-z]|[A-Z]) :- Find the first character that is either upper or lower case. | + | ::;([a-z]|[A-Z]) :- Find the first character that is either upper or lower case. |
− | ;[a-z]+ :- Find at least one to many characters that are lower case only. | + | ::;[a-z]+ :- Find at least one to many characters that are lower case only. |
− | ;[A-Z]+ :- Find at least one to many characters that are upper case only. | + | ::;[A-Z]+ :- Find at least one to many characters that are upper case only. |
− | ;[a-z]+ :- Find at least one to many characters that are lower case only. | + | ::;[a-z]+ :- Find at least one to many characters that are lower case only. |
− | ;(\W|\b) :- Find any character that is not a word character or is the end of line. | + | ::;(\W|\b) :- Find any character that is not a word character or is the end of line. |
+ | |||
+ | == Find and replace using regular expressions. == | ||
+ | |||
+ | Q. I use regular expressions to find text a lot. Now I need to | ||
+ | replace text (or in the current case append new text). | ||
+ | |||
+ | A. What you're after is called 'capturing groups'. The text editor in | ||
+ | Eclipse does it. I've requested it as an enhancement to LPEX, so I | ||
+ | think it's "on the list". | ||
+ | |||
+ | The problem with the text editor is that it sees the date area and | ||
+ | sequence numbers as part of the text so anything using beginning of the | ||
+ | line (^) logic is much trickier. For what you're after it might work. | ||
+ | Add the member to an iSeries Project. Right click the member, then open | ||
+ | with text editor. | ||
+ | |||
+ | Find: reffld(\([A-Z]*\))$ | ||
+ | Replace: REFFLD$1 ALWNULL | ||
+ | |||
+ | The ( ) around the regular expression \([A-Z]*\) marks it as a capturing | ||
+ | group. $1 in the replace is set to whatever the first capturing group | ||
+ | finds. You can nest capturing groups and reference them within the find | ||
+ | as well. Hit F1 in the find dialog to get info about the regular | ||
+ | expressions. | ||
+ | |||
+ | Copied from a WDSC-L repsonse by Adam Glauser [http://archive.midrange.com/wdsci-l/200605/msg00295.html WDSC-L] | ||
+ | [[User:Mattt|Mattt]] 13:47, 29 June 2007 (CDT) | ||
+ | |||
+ | == Find a given subprocedure interface == | ||
+ | ^.{5}d\s*ProcedureName\s*pi | ||
+ | |||
+ | :The regular expression is broken down like this | ||
+ | ::;^ :- Find the beginning of a line | ||
+ | ::;.{5} :- Match any 5 characters. Could be sequence numbers, blanks or a mod mark here. | ||
+ | ::;d :- Match the 'd' in column 6 | ||
+ | ::;\s* :- There could be spaces. * means zero or more. | ||
+ | ::;ProcedureName :- Find the procedure with this name. | ||
+ | ::;\s* :- There could be spaces between the procedure name and the PI. | ||
+ | ::;pi :- Find the PI - the procedure interface. | ||
+ | |||
+ | ==Find XXX...TAG== | ||
+ | Example: Searching for a target of a GOTO in RPG. The actual source code looks like | ||
+ | <br><code> C AROUND TAG</code><br> | ||
+ | |||
+ | So we're looking for the target of GOTO AROUND.<br> | ||
+ | |||
+ | To search for this from the command line, <br> | ||
+ | {{code|findText regularExpression around\s+tag}} <br> | ||
+ | |||
+ | To search for this from the search dialogue (Edit;Find/Replace), <br> | ||
+ | {{code|around\s+tag<br>}} | ||
+ | |||
+ | ...and check the ''Regular expression'' box. | ||
+ | |||
+ | *The key here is that we're using a regular expression to do the work. | ||
+ | *This particular expression is looking for the literal characters '''around''' followed by one or more white spaces (\s+) followed by the literal characters '''tag'''. | ||
+ | *Note that the Java regular expression rules are in use. (case sensitive) [http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html] | ||
+ | * Also in WDSC Help,Help contents Search on 'Regular Expression Grammar', click on 'Regular Expression Grammar to see ALL the codes. | ||
+ | |||
+ | *This may not seem like a very useful thing until you try to search for '''END TAG'''. | ||
+ | *Searching for ''end'' can be a slow process given the number of ways those 3 letters are used! | ||
+ | |||
+ | *An additional use is when you don't know if the target of your search is a TAG or an ENDSR (yes, you can GOTO an ENDSR!) | ||
+ | **This regexp is useful for that situation:<br> | ||
+ | <code>findText regularExpression around\s+(tag|endsr)</code><br> | ||
+ | |||
+ | Here, the items in the parentheses indicate '''or''', so we are searching for<br> | ||
+ | <'''around'''> <...some spaces...> <either '''tag''' or '''endsr'''><br> | ||
+ | |||
+ | Neat! | ||
+ | |||
+ | ==Reference== | ||
+ | |||
+ | {| class="wikitable" border="1" | ||
+ | |+ Regexp Quantifiers | ||
+ | ! Construct!! Meaning | ||
+ | |- | ||
+ | | ? || Exactly one | ||
+ | |- | ||
+ | | {n} || Exactly n times | ||
+ | |- | ||
+ | | {n,} ||At least n times | ||
+ | |- | ||
+ | | {n,m} ||At least n times, but not more than m times | ||
+ | |- | ||
+ | | * || Zero or more times | ||
+ | |- | ||
+ | | + || One or more times | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" border="1" | ||
+ | |+ Regexp predefined character classes | ||
+ | ! Construct !! Meaning | ||
+ | |- | ||
+ | | . || Any character | ||
+ | |- | ||
+ | | \d || A digit [0-9] | ||
+ | |- | ||
+ | | \D || A non-digit: [^0-9] | ||
+ | |- | ||
+ | | \s || A whitespace character: [ \t\n\x0B\f\r] | ||
+ | |- | ||
+ | | \S || A non-whitespace character: [^\s] | ||
+ | |- | ||
+ | | \w || A word character: [a-zA-Z_0-9] | ||
+ | |- | ||
+ | | \W || A non-word character: [^\w] | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" border="1" | ||
+ | |+ Regexp character classes | ||
+ | ! Construct !! Meaning | ||
+ | |- | ||
+ | | . || Any character | ||
+ | |- | ||
+ | | [abc]|| a, b, or c (simple class) | ||
+ | |- | ||
+ | | [^abc] || Any character except a, b, or c (negation) | ||
+ | |- | ||
+ | | [a-zA-Z] || a through z or A through Z, inclusive (range) | ||
+ | |- | ||
+ | | [a-d[m-p]] || a through d, or m through p: [a-dm-p] (union) | ||
+ | |- | ||
+ | | [a-z&&[def]] || d, e, or f (intersection) | ||
+ | |- | ||
+ | | [a-z&&[^bc]] || a through z, except for b and c: [ad-z] (subtraction) | ||
+ | |- | ||
+ | | [a-z&&[^m-p]] || a through z, and not m through p: [a-lq-z](subtraction) | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" border="1" | ||
+ | |+ Regexp boundary matchers | ||
+ | ! Construct !! Meaning | ||
+ | |- | ||
+ | | ^ || The beginning of a line | ||
+ | |- | ||
+ | | $ || The end of a line | ||
+ | |- | ||
+ | | \b || A word boundary | ||
+ | |- | ||
+ | | \B || A non-word boundary | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" border="1" | ||
+ | |+ Regexp logical operators | ||
+ | ! Construct !! Meaning | ||
+ | |- | ||
+ | | XY || X followed by Y | ||
+ | |- | ||
+ | | X|Y || Either X or Y | ||
+ | |- | ||
+ | | (X) || X as a capturing group | ||
+ | |} | ||
+ | |||
+ | |||
+ | |||
+ | == Find a sequence number. == | ||
+ | Sometimes, shop standards require NOT resequencing source member line numbers during each save. In situations like that, the standard Lpex Ctrl-L to position to a line does not work. Ctrl-L positions to an RRN; n lines from the top rather than to sequence number 3.01 (which might be 15 lines from the top.) | ||
+ | |||
+ | To find a sequence number, the command <code>locate sequenceNumber 301</code> will position the cursor at sequence number 3.01. If there is no 3.01, a message to that effect will result. Alternatively, one can bind <code>locateSequenceLine</code> to a key sequence, which will operate much like Ctrl-L by popping up a window and allowing entry of a sequence number to position to. | ||
+ | |||
+ | |||
+ | |||
+ | == Find a date. == | ||
+ | To find lines changed on a certain date (like SEU F14): | ||
+ | * Ctrl+Shift+d | ||
+ | * Edit > Find other > Find date | ||
+ | * Right click in the source, Filter view > Date | ||
+ | |||
+ | |||
+ | == Further references == | ||
+ | * [[WDSC shortcuts]] | ||
+ | * [[WDSC tips]] | ||
+ | |||
+ | |||
+ | == Categories== | ||
+ | [[Category:WDSC]] |
Latest revision as of 19:47, 21 May 2014
WDSC Find Tips - A useful ways to search for text in members/editors
Contents
Find camel case words.
- Open find with Ctrl-F
- Key in "([a-z]|[A-Z])[a-z]+[A-Z]+[a-z]+(\W|\b)" (without the quotes) into the Find box (Alt-F)
- Choose case sensitive (Alt-C)
- Whole word (Alt-O)
- Regular expression (Alt-X)
- The regular expression is broken down like this
- ([a-z]|[A-Z])
- - Find the first character that is either upper or lower case.
- [a-z]+
- - Find at least one to many characters that are lower case only.
- [A-Z]+
- - Find at least one to many characters that are upper case only.
- [a-z]+
- - Find at least one to many characters that are lower case only.
- (\W|\b)
- - Find any character that is not a word character or is the end of line.
Find and replace using regular expressions.
Q. I use regular expressions to find text a lot. Now I need to replace text (or in the current case append new text).
A. What you're after is called 'capturing groups'. The text editor in Eclipse does it. I've requested it as an enhancement to LPEX, so I think it's "on the list".
The problem with the text editor is that it sees the date area and sequence numbers as part of the text so anything using beginning of the line (^) logic is much trickier. For what you're after it might work. Add the member to an iSeries Project. Right click the member, then open with text editor.
Find: reffld(\([A-Z]*\))$ Replace: REFFLD$1 ALWNULL
The ( ) around the regular expression \([A-Z]*\) marks it as a capturing group. $1 in the replace is set to whatever the first capturing group finds. You can nest capturing groups and reference them within the find as well. Hit F1 in the find dialog to get info about the regular expressions.
Copied from a WDSC-L repsonse by Adam Glauser WDSC-L Mattt 13:47, 29 June 2007 (CDT)
Find a given subprocedure interface
^.{5}d\s*ProcedureName\s*pi
- The regular expression is broken down like this
- ^
- - Find the beginning of a line
- .{5}
- - Match any 5 characters. Could be sequence numbers, blanks or a mod mark here.
- d
- - Match the 'd' in column 6
- \s*
- - There could be spaces. * means zero or more.
- ProcedureName
- - Find the procedure with this name.
- \s*
- - There could be spaces between the procedure name and the PI.
- pi
- - Find the PI - the procedure interface.
Find XXX...TAG
Example: Searching for a target of a GOTO in RPG. The actual source code looks like
C AROUND TAG
So we're looking for the target of GOTO AROUND.
To search for this from the command line,
findText regularExpression around\s+tag
To search for this from the search dialogue (Edit;Find/Replace),
around\s+tag
...and check the Regular expression box.
- The key here is that we're using a regular expression to do the work.
- This particular expression is looking for the literal characters around followed by one or more white spaces (\s+) followed by the literal characters tag.
- Note that the Java regular expression rules are in use. (case sensitive) [1]
- Also in WDSC Help,Help contents Search on 'Regular Expression Grammar', click on 'Regular Expression Grammar to see ALL the codes.
- This may not seem like a very useful thing until you try to search for END TAG.
- Searching for end can be a slow process given the number of ways those 3 letters are used!
- An additional use is when you don't know if the target of your search is a TAG or an ENDSR (yes, you can GOTO an ENDSR!)
- This regexp is useful for that situation:
- This regexp is useful for that situation:
findText regularExpression around\s+(tag|endsr)
Here, the items in the parentheses indicate or, so we are searching for
<around> <...some spaces...> <either tag or endsr>
Neat!
Reference
Construct | Meaning |
---|---|
? | Exactly one |
{n} | Exactly n times |
{n,} | At least n times |
{n,m} | At least n times, but not more than m times |
* | Zero or more times |
+ | One or more times |
Construct | Meaning |
---|---|
. | Any character |
\d | A digit [0-9] |
\D | A non-digit: [^0-9] |
\s | A whitespace character: [ \t\n\x0B\f\r] |
\S | A non-whitespace character: [^\s] |
\w | A word character: [a-zA-Z_0-9] |
\W | A non-word character: [^\w] |
Construct | Meaning |
---|---|
. | Any character |
[abc] | a, b, or c (simple class) |
[^abc] | Any character except a, b, or c (negation) |
[a-zA-Z] | a through z or A through Z, inclusive (range) |
[a-d[m-p]] | a through d, or m through p: [a-dm-p] (union) |
[a-z&&[def]] | d, e, or f (intersection) |
[a-z&&[^bc]] | a through z, except for b and c: [ad-z] (subtraction) |
[a-z&&[^m-p]] | a through z, and not m through p: [a-lq-z](subtraction) |
Construct | Meaning |
---|---|
^ | The beginning of a line |
$ | The end of a line |
\b | A word boundary |
\B | A non-word boundary |
Construct | Meaning |
---|---|
XY | X followed by Y |
Y | Either X or Y |
(X) | X as a capturing group |
Find a sequence number.
Sometimes, shop standards require NOT resequencing source member line numbers during each save. In situations like that, the standard Lpex Ctrl-L to position to a line does not work. Ctrl-L positions to an RRN; n lines from the top rather than to sequence number 3.01 (which might be 15 lines from the top.)
To find a sequence number, the command locate sequenceNumber 301
will position the cursor at sequence number 3.01. If there is no 3.01, a message to that effect will result. Alternatively, one can bind locateSequenceLine
to a key sequence, which will operate much like Ctrl-L by popping up a window and allowing entry of a sequence number to position to.
Find a date.
To find lines changed on a certain date (like SEU F14):
- Ctrl+Shift+d
- Edit > Find other > Find date
- Right click in the source, Filter view > Date
Further references