Difference between revisions of "WDSC Find Tips"

From MidrangeWiki
Jump to: navigation, search
(Find and replace using regular expressions.)
(Find and replace using regular expressions.)
Line 21: Line 21:
 
A. What you're after is called 'capturing groups'.  The text editor in  
 
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
 
Eclipse does it.  I've requested it as an enhancement to LPEX, so I
think  
+
think it's "on the list".
it's "on the list".
 
  
 
The problem with the text editor is that it sees the date area and  
 
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  
 
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.
 
line (^) logic is much trickier.  For what you're after it might work.
Add  
+
Add the member to an iSeries Project.  Right click the member, then open
the member to an iSeries Project.  Right click the member, then open
+
with text editor.
with  
 
text editor.
 
  
 
Find: reffld(\([A-Z]*\))$
 
Find: reffld(\([A-Z]*\))$
Line 36: Line 33:
  
 
The ( ) around the regular expression \([A-Z]*\) marks it as a capturing
 
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  
 
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
 
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  
 
as well.  Hit F1 in the find dialog to get info about the regular  
 
expressions.
 
expressions.
 +
 +
Copied from a WDSC-L repsonse by Adam Glauser [http://archive.midrange.com/wdsci-l/200605/msg00295.html]
  
 
== Categories==
 
== Categories==
 
[[Category:WDSC]]
 
[[Category:WDSC]]

Revision as of 18:40, 29 June 2007

WDSC Find Tips - A useful ways to search for text in members/editors

Find camel case words.

  1. Open find with Ctrl-F
  2. Key in "([a-z]|[A-Z])[a-z]+[A-Z]+[a-z]+(\W|\b)" (without the quotes) into the Find box (Alt-F)
  3. Choose case sensitive (Alt-C)
  4. Whole word (Alt-O)
  5. Regular expression (Alt-X)
The regular expression is boken 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 [1]

Categories